Validate procedure executed twice?

Here's an odd one in VB6.

Create a form with a button on it and a text box. Button's CausesValidation property set to true.

Code something (e.g. debug.print "hi") in the text box's validate procedure.

When I use the mouse to click on the button the MyTextBox_Validate procedure is executed twice. If I tab from text box to button, it is only executed once, as it should be.

Why is this the case, and how can I stop it?

PS - I only introduced the text box to provide an easy example. I initially observed this with a list view.

PPS - I've rated the question 20 points because I suspect the answer might be "Sorry, but that's the way it works in VB6". As I don't believe in shooting the messenger, I'll award the 20 points and an "A" to a convincing answer along those lines. I'll increase the points for an actual solution.

Thanks

Pino
LVL 10
caraf_gAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TempharCommented:
Toggle breakpoint in the sub validate.
Then press F8 to debug the program,note
after the first executing,how the program executes the second.

    Can you found the reason?

    Good lucky.
0
caraf_gAuthor Commented:
Hi Temphar,

Tried that; I should have mentioned this in my question. If you step through the code, it steps through the Validate procedure twice in succession, without executing any other code in between.

Thanks

Pino
0
TimCotteeHead of Software ServicesCommented:
Cannot reproduce this! I only get one validate event as you would expect.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

caraf_gAuthor Commented:
Tim,

Now you've got me worried....

You sure you used the mouse and not the tab key (have to eliminate all possibilities)?
0
caraf_gAuthor Commented:
This is worrying indeed. I just checked with a colleague and he could not reproduce it either!

OK, this narrows down the possibilities.

I'm using Windows NT SP5, and VB6 with SP3.

Does anyone know about any issues wrt those versions of the software?
0
EDDYKTCommented:
I can't reproduce too. I get only 1 event as well.
0
TimCotteeHead of Software ServicesCommented:
Tried it any which way but it worked fine each way.
0
tureCommented:
I also get only one execution of the validation procedure.
0
SicilianCommented:
Hey
   This is a bug in VB and I've just read about it recently. You can get around it by (in your example) setting the focus to the button and then back to the textbox in the validate event of the textbox.
   Hope this helps.

Sicilian
0
caraf_gAuthor Commented:
Hi Sicilian,

It would be nice if you could post a URL or a reference to an article here...

All,

Now this is the weirdest thing. Just closed VB and went back in again, and guess what....

It doesn't happen anymore!

Spooky, eh? And that the day AFTER halloween.
0
SicilianCommented:
Sorry
   I can't duplicate the error either. Where I read it was www.tcp.ca/Welcome.asp
   Take a look at the back issue July99 under VB Tutorial.
   Doesn't happen anymore? Freaky.

Sicilian
0
YellowSnowCommented:
Can't find it, Sicilian....
0
MattiCommented:
Hi!


I try this debug method, you shuld also begause now you might get someting which causes that extra event.

I layed two textboxes on a form the nr 2 do not have any code.

-Can't reproduce it whit two textboxes, is there some other Mouse_event code which may temporary take the Focus out of textbox?

-Are you sure that all your VB files are those which come whit SP3 or VB installation, there are some betaversions available and these files have some times caused problems before.

-Now you say you have closed VB and backagain and then the problem has been solved???. Nothing realy solves by it self someting must have effected there.
If there is a memory leak in one componet or resourses just get somehow exhausted the VB IDE got some behavior problems. Try to give some load if you get them back.

I do not have my VB6 on NT4 SP5 (it is on 98) and now i also got a new VB 6 test enviroment whit 2000 Release Canditate 2 later I try this in there.

Private ntimes&

Private Sub Text1_GotFocus()
Debug.Print "Gotfocus" & ntimes
End Sub

Private Sub Text1_LostFocus()
Debug.Print "Lostfocus" & ntimes
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "MouseDown" & ntimes
End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "MouseUp" & ntimes
End Sub

Private Sub Text1_Validate(Cancel As Boolean)
ntimes = ntimes + 1
Debug.Print Cancel & " " & ntimes
End Sub



Matti
0
YellowSnowCommented:
Are you using a timer to set focus to another control?
0
caraf_gAuthor Commented:
Matti, YellowSnow,

No...

Like I said, I started from scratch:

I created a brand new project, and the only things I did was:

- Place a new text box on the form
- Place a new command button on the form
- Add the code debug.print "Hi" to the Validate procedure.

That, without any further additions, caused my problem.

Good point about the VB installation. As we often take stuff from MSDN CDs I cannot guarantee that what I'm using is officially released product, though it should be, as far as I know.

I'll check that.
0
amebaCommented:
I don't use Validate Event! Hope this helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
caraf_gAuthor Commented:
It does indeed. I've since come to the same conclusion ;-)
0
caraf_gAuthor Commented:
Hm... out of all suggestions this is the best one, I guess...

So boys 'n girls, marvel at M$ newest addition to VB and then forget about it.
0
amebaCommented:
Thanks for your points.
I am using TextBox_Change event to do validation.
The event code is not in Form, but in a separated class, e.g. cwSimpleText or cwNumerix
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.