Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Conversion to VB results in errors

Conversion to VB results in errors

Scheduled Pinned Locked Moved C#
csharphelpquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sonhospa
    wrote on last edited by
    #1

    Dear all :-) I converted a sample from C# to VB and get an error message. It looks simple, but still I don't understand... Would it be possible that C# allows calling an event directly, while VB doesn't? Or did my conversion tool go wrong? :doh: Here's the short sample code:

    private void OnWaveControlContextMenuPopup(ContextMenu menu)
    {
    if (this.WControlContextMenuPopup == null)
    return;
    this.WControlContextMenuPopup(menu);
    }

    where WControlContextMenuPopup is defined as an event:

    public event WControlContextMenuPopupDelegate WaveControlContextMenuPopup;

    After conversion I get the error message "Public Event WControlContextMenuPopup in an event and cannot be called directly. Use 'RaiseEvent'...". The error is shown in lines 2 and 5 of the converted code:

    Private Sub OnWControlContextMenuPopup(menu As ContextMenu)
        If Me.WControlContextMenuPopup Is Nothing Then             <-----
            Return
        End If
        Me.WControlContextMenuPopup(menu)                          <-----
    End Sub
    

    What would I have to change in the VB code to get the required result without error? Thanks for some insight... :cool: Mick

    Richard DeemingR D 2 Replies Last reply
    0
    • S Sonhospa

      Dear all :-) I converted a sample from C# to VB and get an error message. It looks simple, but still I don't understand... Would it be possible that C# allows calling an event directly, while VB doesn't? Or did my conversion tool go wrong? :doh: Here's the short sample code:

      private void OnWaveControlContextMenuPopup(ContextMenu menu)
      {
      if (this.WControlContextMenuPopup == null)
      return;
      this.WControlContextMenuPopup(menu);
      }

      where WControlContextMenuPopup is defined as an event:

      public event WControlContextMenuPopupDelegate WaveControlContextMenuPopup;

      After conversion I get the error message "Public Event WControlContextMenuPopup in an event and cannot be called directly. Use 'RaiseEvent'...". The error is shown in lines 2 and 5 of the converted code:

      Private Sub OnWControlContextMenuPopup(menu As ContextMenu)
          If Me.WControlContextMenuPopup Is Nothing Then             <-----
              Return
          End If
          Me.WControlContextMenuPopup(menu)                          <-----
      End Sub
      

      What would I have to change in the VB code to get the required result without error? Thanks for some insight... :cool: Mick

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Try something like this:

      Private Sub OnWControlContextMenuPopup(menu As ContextMenu)
      RaiseEvent WControlContextMenuPopup(menu)
      End Sub


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S 1 Reply Last reply
      0
      • S Sonhospa

        Dear all :-) I converted a sample from C# to VB and get an error message. It looks simple, but still I don't understand... Would it be possible that C# allows calling an event directly, while VB doesn't? Or did my conversion tool go wrong? :doh: Here's the short sample code:

        private void OnWaveControlContextMenuPopup(ContextMenu menu)
        {
        if (this.WControlContextMenuPopup == null)
        return;
        this.WControlContextMenuPopup(menu);
        }

        where WControlContextMenuPopup is defined as an event:

        public event WControlContextMenuPopupDelegate WaveControlContextMenuPopup;

        After conversion I get the error message "Public Event WControlContextMenuPopup in an event and cannot be called directly. Use 'RaiseEvent'...". The error is shown in lines 2 and 5 of the converted code:

        Private Sub OnWControlContextMenuPopup(menu As ContextMenu)
            If Me.WControlContextMenuPopup Is Nothing Then             <-----
                Return
            End If
            Me.WControlContextMenuPopup(menu)                          <-----
        End Sub
        

        What would I have to change in the VB code to get the required result without error? Thanks for some insight... :cool: Mick

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        C# and VB have differing syntax for doing the same thing. C# uses a syntax that is identical to calling an actual method. The error mesage tells you exactly what to do.

        RaiseEvent WControlContextMenuPopup(menu)
        

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        S 1 Reply Last reply
        0
        • D Dave Kreskowiak

          C# and VB have differing syntax for doing the same thing. C# uses a syntax that is identical to calling an actual method. The error mesage tells you exactly what to do.

          RaiseEvent WControlContextMenuPopup(menu)
          

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          S Offline
          S Offline
          Sonhospa
          wrote on last edited by
          #4

          Thank you for your answer. Will I just ignore the whole "If..." part then? Because "If RaiseEvent..." doesn't work either. What is it actually supposed to do? Check for the result of an event???

          D 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Try something like this:

            Private Sub OnWControlContextMenuPopup(menu As ContextMenu)
            RaiseEvent WControlContextMenuPopup(menu)
            End Sub


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            S Offline
            S Offline
            Sonhospa
            wrote on last edited by
            #5

            Thank you, Richard. Is it correct to leave the "if... end if" part away completely?

            Richard DeemingR 1 Reply Last reply
            0
            • S Sonhospa

              Thank you for your answer. Will I just ignore the whole "If..." part then? Because "If RaiseEvent..." doesn't work either. What is it actually supposed to do? Check for the result of an event???

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Yes, you ignore the if code. All it does is check to see if a subscriber is attached before trying to raise the event. If VB.NET, with RaiseEvent, you don't have to do that.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak

              S 1 Reply Last reply
              0
              • S Sonhospa

                Thank you, Richard. Is it correct to leave the "if... end if" part away completely?

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                Yes, that's correct; RaiseEvent handles that check for you.


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                S 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  Yes, you ignore the if code. All it does is check to see if a subscriber is attached before trying to raise the event. If VB.NET, with RaiseEvent, you don't have to do that.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  S Offline
                  S Offline
                  Sonhospa
                  wrote on last edited by
                  #8

                  Thank you for your help, and have a nice evening! :thumbsup:

                  1 Reply Last reply
                  0
                  • Richard DeemingR Richard Deeming

                    Yes, that's correct; RaiseEvent handles that check for you.


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    S Offline
                    S Offline
                    Sonhospa
                    wrote on last edited by
                    #9

                    Thanks for helping, Richard - have a nice evening! :java:

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups