-
I have a code that I need explained to me line by line.
Private Sub txtInputBox_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "+" Then
KeyAscii = 0
txtDisplayBox.Text = Val(txtDisplayBox.Text) + Val(txtInputBox.Text)
txtInputBox.Text = ""
End If
End Sub
________________________________________________
Now when I ran the code, I could not finish putting the sentence in the text box when I get a message automatically saying It's a palindrom!!
-
<?>
Code:
'txtInputBox is a text box and the event is the keypress
Private Sub txtInputBox_KeyPress(KeyAscii As Integer)
'if the + key is pressed then
If Chr(KeyAscii) = "+" Then
'the key = nothing (pretend the key doesn't exist)
KeyAscii = 0
'then in txtDisplayBox text box add the value or it ot the value or txtinputbox
txtDisplayBox.Text = Val(txtDisplayBox.Text) + Val(txtinputbox.Text)
'set the value of txtinputbox to nothing
txtinputbox.Text = ""
'end the if statement
End If
'exit sub
End Sub
-
hardly surprising about the message coming up before you have finished typing the sentence! It is because the computer is doing the check every single time you press a letter!
do not use the KEYPRESS event for this procedure, because you will never get far enough to do the test properly.
Perhaps you could paste the code into a button's click event or something.