Computer Hope

Software => Computer programming => Topic started by: simplyTechy100 on April 03, 2014, 05:59:02 PM

Title: Visual Basic - Trying to fix "End of statement expected"
Post by: simplyTechy100 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 (http://www.weebly.com/uploads/1/1/0/2/11027161/login.vb) is the Login.vb.
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: BC_Programmer on April 03, 2014, 07:57:01 PM
-Your If statements are all compile-time conditional compilation (http://msdn.microsoft.com/en-us/library/x435tkbk.aspx).
-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.
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: simplyTechy100 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
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: simplyTechy100 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.
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: BC_Programmer 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.
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: simplyTechy100 on April 03, 2014, 09:12:11 PM
Now you raised the error amount on the browser from 1 to 4...
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: BC_Programmer 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?
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: Geek-9pm 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.
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: simplyTechy100 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
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: BC_Programmer 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.
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: simplyTechy100 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
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: camerongray 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.
Title: Re: Visual Basic - Trying to fix "End of statement expected"
Post by: Squashman 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.