PDA

View Full Version : For those who know a bit about Visual Basics Prgramming!!



Drunken Tiger
03-13-2002, 02:50 AM
Private Sub cmd_ok_Click()
'This checks that the login name and password is correct'
If txb_login <> "DT" Then
MsgBox "Incorrect Login Name"
Else
txb_password = ""
txb_login.SetFocus

'If login name is correct it will continue to check the password'
If txb_password <> "AGN" Then
MsgBox " Incorrect Password"
Else
txb_password = ""
txb_login.SetFocus

'When both the login name and password have been verifed it will open the next screen"
GTA3Open.Show
txb_password = ""
Gta3.Hide

End If
End If
End Sub
Whats wrong!! I always get the "Incorrect Login Name" message!! But I entered the right one in!! Please help me!?!
This is so draining!!:angry:

inori
03-13-2002, 03:43 AM
You really should ask this in the Programming forum...

But as to the answer to your question, three things jump out at me.

#1: Try running your code in the debugger. Put a breakpoint on the first line of the function and trace through its flow. Just before the if statement executes, check the value of the variable you're testing to make sure it's what you think it is.

#2: Make sure you're typing your inputs in capital letters. The <> operator requires exact equality, including case, so "AGN" <> "agn".

#3: On line six, you set the password to "". On line ten, you test the password against "AGN". This test will always fail, because you just set the password to something other than "AGN" four lines ago.

Drunken Tiger
03-13-2002, 04:05 AM
#1: Try running your code in the debugger. Put a breakpoint on the first line of the function and trace through its flow. Just before the if statement executes, check the value of the variable you're testing to make sure it's what you think it is.

Im a newbie at this so i have no idea what you are talking about.. sorry!!


#2: Make sure you're typing your inputs in capital letters. The <> operator requires exact equality, including case, so "AGN" <> "agn".
I've done that..:D

#3: On line six, you set the password to "". On line ten, you test the password against "AGN". This test will always fail, because you just set the password to something other than "AGN" four lines ago.
Do you think you can give me an example??




As i said before.. im a newbie at this!! :confused:

inori
03-13-2002, 04:52 AM
Originally posted by DrUnKeN TiGeR

Private Sub cmd_ok_Click()
'This checks that the login name and password is correct'
If txb_login <> "DT" Then
MsgBox "Incorrect Login Name"
Else
txb_password = "" ' This is line six
txb_login.SetFocus

'If login name is correct it will continue to check the password'
If txb_password <> "AGN" Then ' This is line ten
MsgBox " Incorrect Password"
Else
txb_password = ""
txb_login.SetFocus

'When both the login name and password have been verifed it will open the next screen
GTA3Open.Show
txb_password = ""
Gta3.Hide

End If
End If
End Sub


Hey, no problem. I've quoted your code (and put it inside CODE and /CODE tags) so it's easier to refer to.

See the line I marked as "This is line six"? That line changes txb_password to "" (the empty string). However, just a few lines later (on the line I marked "This is line ten"), you perform the test "txb_password <> "AGN" ". That test will always be true. Why? Well, you just finished changing txb_password to "", and "" <> "AGN".

Here's another debugging tip: You can add either or both of these two lines anywhere inside your procedure, so you can check the values of the variables you are using. This can help you tell what values your variables really have.


' This line pops up a message with the value of the txb_login variable
MsgBox "txb_login = " & txb_login
' This line does the same for the txb_password variable
MsgBox "txb_password = " & txb_password

Good luck!

Drunken Tiger
03-13-2002, 05:13 AM
Thanks alot Inori!! your a lifesaver!!:thumbsup:
Do you do this at school??? Or are you just good at it???

inori
03-13-2002, 05:25 AM
Well, actually, I get paid to teach computer science. How cool is that? They pay me to do my (second) favorite thing in the whole world! :thumbsup: I'm a grad student, and a TA, at UC Berkeley, studying computer science.

Glad I could be of help. If you have more questions, wander on over to the Programming forum ... there, you will find many others like me who like to answer questions like this one. (Wow, I used the word "like" three times in that sentence...)

Drunken Tiger
03-13-2002, 05:54 AM
Cool, and thanks ill most probably take you up on your offer!!:):)