| | |
End if statements
Thread Solved |
hi guys, i know this might look like a n00b's homework assignment - but it aint, im studying VB for myself.
Im trying to do this tutorial over here, cuz everybody said it's good
http://www.profsr.com/vb/vbless04.htm
Prob is when i try to press the confirm button, error message pops up saying "end if without block if"? I've tried organizing my code but that doesn't seem to work... I don't get it, am I using incorrect syntax?
Here's the code for the confirm button below
Thanks ^^
Im trying to do this tutorial over here, cuz everybody said it's good
http://www.profsr.com/vb/vbless04.htm
Prob is when i try to press the confirm button, error message pops up saying "end if without block if"? I've tried organizing my code but that doesn't seem to work... I don't get it, am I using incorrect syntax?
Here's the code for the confirm button below
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub confirm_Click() Dim hoursbox As Integer Dim deductbox As Integer Dim rate As Integer Dim grosalary As String Dim netsalary As String If op1.Value = False _ And op2.Value = False _ And op3.Value = False Then grosalary = "invalid" And netsalary = "invalid" End If If op1.Value = True Then rate = 10 End If If op2.Value = True Then rate = 20 End If If op3.Value = True Then rate = 30 End If grosalary = rate * hoursbox netsalary = grosalary - deductbox End Sub
Thanks ^^
Last edited by Comatose; Jun 7th, 2006 at 6:31 am.
Nobody2ph is an agent of the Forgeway Network http://forgeway.cjb.net/
•
•
Join Date: Jun 2006
Posts: 37
Reputation:
Solved Threads: 2
try this,,, 

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command1_Click() Dim hoursbox As Integer Dim deductbox As Integer Dim rate As Integer Dim grosalary As String Dim netsalary As String If op1.Value = False _ And op2.Value = False _ And op3.Value = False Then grosalary = "invalid" netsalary = "invalid" End If If op1.Value = True Then rate = 10 If op2.Value = True Then rate = 20 If op3.Value = True Then rate = 30 grosalary = rate * hoursbox netsalary = grosalary - deductbox End Sub
Last edited by Comatose; Jun 7th, 2006 at 6:31 am.
One problem that a lot of people don't understand is that an if statement has 2 different syntax. The only time you have to "end if" an if statement, is when the if statement is on more than 1 line (or if it does more than one thing). So for example, if I want to make this program change the value of a variable, display a msgbox and leave the sub, I would do this:
However, let's say all I want to do is change the variable, and that's it.... just change the variable and move on, if x = 5:
And that will work just fine..... in fact, it will give an error if you put a end if..... without have a "block" of code.
Another thing to keep in mind, is that it really isn't a good practice to put code that should be on 1 line, in more than 1 line. For example, the underscores used in your first if block. While VB allows you to do this (and it's supposed to be for readability) you shouldn't. Each line should represent a different purpose..... it keeps things in order. If you are comfortable programmang with the _, then keep doing it, but be aware on team projects and larger scale apps, you will kick yourself in the rump for it.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
somevariable = 1 if x = 5 then somevariable = 10 msgbox "changed somevariable to 10" exit sub end if
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
somevariable = 1 if x = 5 then somevariable = 10
Another thing to keep in mind, is that it really isn't a good practice to put code that should be on 1 line, in more than 1 line. For example, the underscores used in your first if block. While VB allows you to do this (and it's supposed to be for readability) you shouldn't. Each line should represent a different purpose..... it keeps things in order. If you are comfortable programmang with the _, then keep doing it, but be aware on team projects and larger scale apps, you will kick yourself in the rump for it.
thanks guys , i understand a lot better now ^^
Nobody2ph is an agent of the Forgeway Network http://forgeway.cjb.net/
![]() |
Similar Threads
- switch statement on String in Java (Java)
- Odd string concatenation behavior? (Perl)
- Linear search (C++)
- getting the text field value (HTML and CSS)
- Serious help needed ASAP error message!!!! (Pascal and Delphi)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Draw text on JPEG
- Next Thread: WaitForEvent if then argument
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






