PDA

View Full Version : Vb if... end if problem


Tr199
14-02-2004, 00:46
i just started to learn visual basic at college in my programming class and i was asked by a freind to make a screen that resembled a keypad and you have to type in a correct code to show the next form.

i have got the input workign but where i have used an IF statement it wants me to put in an END IF in some but i dont know where.

this is the code:

Private Sub Command2_Click()

If Text1 = "143121" Then End If
Form2.Show

End Sub

labelling is a bit rubbish but im just testing it out at the moment.

does anyone know where i have to put the end if statement to get it to work?

cheers
adam

(P.S. i tried asking my teacher but hes a right old miserable git and he wont tell me coz its not relavent to the work we are doing at the moment)

Forthy
14-02-2004, 12:51
After "Form2.show" would be my educated guess, but I don't know for sure.

If Text1 = "143121" Then
Form2.Show
End If

sambartle
15-02-2004, 08:22
since theres only one command cant you just do:

If Text1 = "143121" Then Form2.Show

And that wont need an end if because its all on one line ( Forthy's way should work too )

Clarksy
15-02-2004, 23:17
VB syntax for if statements:


IF xxx THEN
...
...
...
...
END IF


xxx is the condifiton your checking for
... is the code you want to execute


if you only want to execute one command then you can do:

IF xxx THEN ....


An END IF is only needed if your IF statement extends beyond one line.