|
-
Apr 30th, 2000, 10:51 PM
#1
Thread Starter
New Member
Hi all,
I've having a bit of a problem in a program I'm creating, and I'm pretty sure it's an error in VB that's causing it. Hopefully someone has seen this error before and will recognise it, so I can learn how to fix it. 
In my project, I have a form which contains a bunch of textboxes, listboxes and comboboxes that the user needs to fill in with a whole bunch of information. They fill this in to begin with (I'll call this "part A") and then they click on a button labelled "Next". This causes everything on the form to be cleared so they can enter more information into the same form, using the same controls. (I'll call this second round of entering information "part B".)
After they've finished entering the info the second time, they click on "Next" again, and this takes them to a new form. This new form has a "Back" button (in case they change their mind) that takes them to the previous form by Hiding the current form and Showing the previous form.
Okay, here's the problem. When the user clicks on Back, and the previous form is Shown, the controls on the previous form contain the information from part A, not part B. This doesn't make any sense at all - when I reshow the form, the controls on the form should contain the information that was last entered ie the part B info. I don't clear this info or anything, yet the info from part A magically appears into the textboxes and listboxes.
Here's the really weird part, that leads me to believe it's VB's fault. When I step through the program line by line, using F8, the program works perfectly! It's only when I run the program normally without stepping that it screws up. Of course, stepping through the program should result in the same output as running the program normally.
Has anyone else seen this before? When showing a form that has previously been hidden, does the contents of the form automatically change by themselves? In case it helps, I'm using VB6, and I've tried my program on two different computers, with the same results. I've also shown the program to several other people, and they were just as stumped. I'm convinced that either (1) There is an error in VB, (2) My program is possessed by the devil, or (3) A poltergeist is behind all of this. I'd be extremely grateful for any ideas. (Sorry to make this so long!)
Justin
A CS student at the University of Western Australia
-
Apr 30th, 2000, 11:45 PM
#2
Member
can you post your code for Next and Back buttons if it is not going to be too much?
-
Apr 30th, 2000, 11:53 PM
#3
Addicted Member
Are you loading the information (lists, etc.. ) in the load or the activate event ? If your loading things in the activate event this code will fire when you go "back" to this form.
This might explain the behavior difference when you step through the code because activate events fire differently in debug mode.
Glenn D
Development/Analyst
-
May 1st, 2000, 02:22 AM
#4
The reason a program may behave differently when run as compared with runing it with f8 is that the latter mode gives the system time to perform work that it may not have the chance to do when running normally. This kind of thing often happens if you have a tight loop that for example does not give the system time to repaint the screen. The correction for this is to add a DoEvents statement in the loop. This says to the computer "go off for a bit and do what you need to do" and then come back. I can't tell you for sure where to place the statement in your case, but try it just before you execute the "Back" code.
-
May 1st, 2000, 04:23 PM
#5
Thread Starter
New Member
Hi all,
Thanks very much for replying mlana, Glenn and MartinLiss. And the award goes to...drumroll please... Glenn!
Glenn pointed out that activate events behave differently when in debug mode. I had never heard of this before (nor had several other people I had asked.) So, what was happening, was that code in the Form_Activate method was being executed that was screwing up the contents of the controls, and I couldn't tell this was going on because this code wasn't executed when stepping through the program.
Well, that's an absolute pain in the @$$, if you ask me. How can you use the debugger if it makes your program behave differently to running your programming normally?!? *sigh* I guess it's not a bug, but it seems a screw-up by Microsoft to me anyway.
Mlana: the only relevant parts of the code for the back and next buttons was a Hide statement to hide the current form and Show statement to show the other form.
MartinLiss: not a bad idea, but I had already considered this, more or less (although I wasn't aware of the DoEvents method). Since all I was doing was reshowing a previous form (and there was no processing or anything that would mean the compiler would "get behind"), I had pretty much ruled this out. (I probably should have mentioned this in my first post, but it was already so damn long...)
Well, I guess that's about it. (The debug mode runs your program differently?!? What a croc!!!) Thanks again everyone for replying - hopefully I'll be able to return the favour sometime. (1100 posts MartinLiss? Got a lot of spare time, huh? Hehe, just kidding.)
Justin
A failing CS student
-
May 1st, 2000, 08:28 PM
#6
Addicted Member
I'm glad I could help. Anytime your depending on events that affect the viewing (or painting) of forms (like the activate) event if works differently in debug mode. I think it has more to do with Windows than it does VB. The activate event fires everytime focus is returned to the form. So when VB is running the code windows continually get focus and screw up the activate events. One way to debug these sort of things is to put debug.print statements in your code.
Glenn D
Development/Analyst
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|