General > Off Topic
Serious weirdness going on here.
PurpleYouko:
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
--- Code: ---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
--- End code ---
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:
Numsgil:
There's a name for this type of bug. I forget exactly...
It's some silly name like Mendelbug or Shrodingerbug, etc. Bug only occurs when you run the program and not when you're debugging it.
PurpleYouko:
Damn annoying pile of crap is my name for it. :angry:
I have been chasing this darn thing for hours now.
Every time I run the program it screws up and outputs a zero but when I set the debug point anywhere except inside the conditional, the stupid thing works perfectly. <_<
I think it hates me. :(
Numsgil:
Maybe it's your method for placing a catch line. Instead of a = a try DoEvents. See if that effects it at all.
Do you have "Option Explicit" at the top of your source, cause if not, it could be a typo bug (the worst kind).
PurpleYouko:
No it isn't a typo. The code above was cut and pasted directly from the program itself.
I just made a stand alone test routine using exactly the same code and it works perfectly every time.
As for the a=a line. I have been using it for years to make a completely innocuous and useless piece of code that will work as a break point. never had it fail before.
I am NOT using option explicit because if I do then it crashes at my database queries every time I try to run them. The "Recordset" object in the ODBC setup is apparently incompatible with it. I can't dim "Recordset" because it is a reserved word but option explicit claims that it is undimensioned. Bit of a catch 22. :wacko:
Anyway I have to go now. Time to go home to the wife, kids and my new kitten. :bigginangel:
Navigation
[0] Message Index
[#] Next page
Go to full version