I have just come across the weirdest thing in some VB code that I am writing.
It should be quite straightforward. I have a textbox in which the user can type anything he wants then using a keypress event I transfer the current value of the textbox to another place after the user presses the enter key.
Seem normal enough? I thought so.
Here is the routine. (note the "a = a" lines are for highlighting as breakpoints and serve no actual function
Private Sub DataEntry_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
If DataEntry.Text = "" Then
DataEntry.Text = "0"
a = a
End If
a = a
DispGrid DataEntry.Text
DataEntry.Visible = False
DataEntry.Text = ""
End Sub
As you can see if the keypress returns anything other than 13 (enter) then the code just leaves the subroutine but when enter is pressed, the current value in the text box is sent to the "DispGrid" routine for output into a flexgrid object.
So what do you think will happen when I run the program?
What actually happens is that no matter what value is in the text box, "0" gets sent to "DispGrid". Weird huh?
It gets worse.
If I set the "a = a" statement inside the "If" statement as a breakpoint then run the program, it catches it and shows a value of "0" in the textbox as there should be if there was no text in it at all.
However (and this is where it gets bizarre) If I set the second "a = a" as the breakpoint and run the program, it skips the first breakpoint completely and the value in the textbox is shown to be whatever it was that I typed in. On continuing, the correct value is sent to "DispGrid" and the program works perfectly as designed.
This is the first, only and I hope last time that I have ever seen the outcome of a program change due to nothing more that highlighting a breakpoint in the code.
This is not supposed to happen :blink: