Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Visual Basic - Trying to fix "End of statement expected"  (Read 32007 times)

0 Members and 1 Guest are viewing this topic.

simplyTechy100

    Topic Starter


    Rookie

    Thanked: 1
    • Experience: Expert
    • OS: Windows 7
    Visual Basic - Trying to fix "End of statement expected"
    « on: April 03, 2014, 05:59:02 PM »
    I am trying to make a Visual Basic OS but I get 3 errors on Login.vb that are all "End of statement expected.
    Code: [Select]
    Public Class Login
    #If TextBox1.Text == Administrator Then
        TextBox2.Text == AdminSuper32
    #End If
    #If Button1.Click Then
        Desktop.Show()
    #End If
    #If TextBox1.Text == Administrator & TextBox2.Text == AdminSuper32 Then
        DeskAdmin.Show()
    #End If

    End Class
    I have all 2 .vb's created. (both fullscreen)
    This is causing me to post here.
    If I revert to (last functional state) or whatever it will remove the #If's that I need for logon, administrator check and Auto-Admin Logon (type Administrator, and poof, the password!)
    I am not sure I can send you the "errored" program. But if you want, I think I can send the Login.vb!
    EDIT: Here is the Login.vb.

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Visual Basic - Trying to fix "End of statement expected"
    « Reply #1 on: April 03, 2014, 07:57:01 PM »
    -Your If statements are all compile-time conditional compilation.
    -None of the executable code exists in a method.
    -Neither Administrator or AdminSuper32 are valid identifiers. You probably meant to quote them.
    -Visual Basic doesn't have a & operator.
    -Visual Basic doesn't have a == operator.
    even changing all of that to:

    Code: [Select]
    Public Class Login
      Public Sub New()
        If TextBox1.Text = "Administrator" Then
            TextBox2.Text = "AdminSuper32"
        End If
        If Button1.Click Then
            Desktop.Show()
        End If
        If TextBox1.Text = "Administrator" And TextBox2.Text = "AdminSuper32" Then
            DeskAdmin.Show()
        End If
      End Sub
    End Class

    I would guess this is supposed to be in a Button event handler.
    I was trying to dereference Null Pointers before it was cool.

    simplyTechy100

      Topic Starter


      Rookie

      Thanked: 1
      • Experience: Expert
      • OS: Windows 7
      Re: Visual Basic - Trying to fix "End of statement expected"
      « Reply #2 on: April 03, 2014, 08:36:45 PM »
      O.O I am actually super confused for Visual Basic..
      Now I have a different program with this problem.
      But only 1. And it is just 1 .vb, and 1 Sub called Browse...
      Code: [Select]
      Public Class Form1
          Public Sub Browse()
      #If Button1.Click() Then
          WebBrowser1.URL = TextBox1.Text
      #End If
          End Sub

      End Class

      simplyTechy100

        Topic Starter


        Rookie

        Thanked: 1
        • Experience: Expert
        • OS: Windows 7
        Re: Visual Basic - Trying to fix "End of statement expected"
        « Reply #3 on: April 03, 2014, 08:55:00 PM »
        Also, for the Login.vb, now I get 1 error and 1 warning..
        Quote
        Warning: 'Public Sub New()' in designer-generated type 'OSVB_0._5.Login' should call InitializeComponent method. //FIXED\\
        Error   : 'Public Event Click(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Visual Basic - Trying to fix "End of statement expected"
        « Reply #4 on: April 03, 2014, 09:09:44 PM »
        O.O I am actually super confused for Visual Basic..
        Now I have a different program with this problem.
        But only 1. And it is just 1 .vb, and 1 Sub called Browse...
        Code: [Select]
        Public Class Form1
            Public Sub Browse()
        #If Button1.Click() Then
            WebBrowser1.URL = TextBox1.Text
        #End If
            End Sub

        End Class

        you are still using conditional compilation. remove the # from your Ifs and End Ifs.

        Also, for the Login.vb, now I get 1 error and 1 warning..

        I think you misunderstood. That segment was not supposed to be "fixed" code. I suggest you read through the Programmer's Guide on MSDN, which should guide you through the creation of some sample programs.
        I was trying to dereference Null Pointers before it was cool.

        simplyTechy100

          Topic Starter


          Rookie

          Thanked: 1
          • Experience: Expert
          • OS: Windows 7
          Re: Visual Basic - Trying to fix "End of statement expected"
          « Reply #5 on: April 03, 2014, 09:12:11 PM »
          Now you raised the error amount on the browser from 1 to 4...

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: Visual Basic - Trying to fix "End of statement expected"
          « Reply #6 on: April 03, 2014, 10:25:46 PM »
          Now you raised the error amount on the browser from 1 to 4...

          I didn't state anywhere that your use of conditional compilation was the only problem.

          Quote
          If Button1.Click() Then
              WebBrowser1.URL = TextBox1.Text
          End If
          What is this supposed to do? Are you simply guessing about what code you should write?
          I was trying to dereference Null Pointers before it was cool.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: Visual Basic - Trying to fix "End of statement expected"
          « Reply #7 on: April 03, 2014, 10:44:17 PM »
          Allow me to say something to the OP.
          BC programmer is well-qualified to assist you, but you're  in making it hard.
          It appears that you have not really read the documentation for Visual Basic or else you skipped over something and tried to copy an example that was not appropriate.
          The key word that starts with the #is not really a program word, it is a directive for the compiler.  Like BC said, it does not control actual program flow, it only qualifies how the compiler will treat your code. In other words, what you did is wrong. Unless you really wanted to do a compiler directive, and even in that case, you're still wrong.
          The compiler directive is something that has to be resolved at compile time, not at run-time. Normally it is something that would resolve immediately to a Boolean value or possibly an integer. It would be used either to select between two alternate forms of the code, or possibly from a list of other discreet  options. Anyway, it does not control the run time code.
          Please use the notation that is given in the Visual Basic documentation for actual programs, and stop trying to use compiler directives.
          End of my rant, I am just trying to help. Pay attention to what BC programmer is telling you. He is the best you can find on this forum for Visual Basic.

          simplyTechy100

            Topic Starter


            Rookie

            Thanked: 1
            • Experience: Expert
            • OS: Windows 7
            Re: Visual Basic - Trying to fix "End of statement expected"
            « Reply #8 on: April 04, 2014, 09:53:55 AM »
            O.O I fixed the error.  Well for the browser.
            Thanks Instructables!
            I got 1 error on the OS... still.
            Code: [Select]
            Public Class Login
                Public Sub New()
                    InitializeComponent()
                    If TextBox1.Text = "Administrator" Then
                        TextBox2.Text = "AdminSuper32"
                    End If
                    If Button1.Click Then -It errors here
                        Desktop.Show()
                    End If
                    If TextBox1.Text = "Administrator" And TextBox2.Text = "AdminSuper32" Then
                        DeskAdmin.Show()
                    End If
                End Sub
            End Class

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: Visual Basic - Trying to fix "End of statement expected"
            « Reply #9 on: April 04, 2014, 10:30:22 AM »
            I got 1 error on the OS... still.
            Surely that error has a name and description and source line number.
            I was trying to dereference Null Pointers before it was cool.

            simplyTechy100

              Topic Starter


              Rookie

              Thanked: 1
              • Experience: Expert
              • OS: Windows 7
              Re: Visual Basic - Trying to fix "End of statement expected"
              « Reply #10 on: April 07, 2014, 05:06:30 AM »
              Quote
              'Public Event Click(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
              Line 7, Column 12
              Login.vb

              camerongray



                Expert
              • Thanked: 306
                • Yes
                • Cameron Gray - The Random Rambings of a Computer Geek
              • Certifications: List
              • Computer: Specs
              • Experience: Expert
              • OS: Mac OS
              Re: Visual Basic - Trying to fix "End of statement expected"
              « Reply #11 on: April 07, 2014, 05:22:08 AM »
              You need to learn Visual Basic before trying to write software in it.  What you are doing there to handle events like a button press is completely wrong - You don't use an if statement, you create methods (subroutines) that are bound to events such as a button being pressed and then when the button is pressed, that method is called.

              Also, name your controls something useful rather than TextBox1 or Button1 unless you want to get in a mess down the line.

              Squashman



                Specialist
              • Thanked: 134
              • Experience: Experienced
              • OS: Other
              Re: Visual Basic - Trying to fix "End of statement expected"
              « Reply #12 on: April 10, 2014, 06:44:39 PM »
              Code: [Select]
              If Button1.Click Then -It errors here
              At least learn how to write a comment.