Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> VB6 Need Help With Object Validation, Any help will be appreciated
mastercomputers
post Aug 20 2005, 01:45 PM
Post #1


PESTICIDAL MANIAC
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



OK, only been using VB6 for less than 2 weeks, but have gone passed expectations and have found things I have overlooked and am now needing either an explanation on how to do it or some good places they will clearly explain how to go about it.

To be honest, I'm not wanting to learn this language, it's just a requirement that I must get out of the way before moving onto a much larger project.

I will apologise now if I speak a lot of C/C++ Objects/Properties/Methods/Functions, I can explain programming better under this language.

So back to VB,

Just to ignore my program, lets say I have a simple form, it has 2 textboxes and a command button to process the information.

Each textbox has field validation, using validate(), so it raises errors to the user as soon as they try leaving the box, so both text boxes must validate before they can leave that box then they can process the information.

However, the first textbox can validate and instead of them changing focus to the second textbox, they click straight on the button, since the first textbox is valid, they're allowed to move on, but they skipped the second textbox and that's the problem.

So I need a means to make sure that both fields contain information before allowing the information to be process. I don't want to use the process button to do this (but will if I can't get it working).

So my intentions is, I'm going to disable this button and want to enable it when both textboxes contain valid information, which means they won't be able to bypass it.

So how would I do this, I think it's called Object Validation, but I'm uncertain if that's VB terminology. While the textbox validation is Field Validation.

So any clues, tips, sites anything that will help me?


Cheers,


MC
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Aug 20 2005, 06:52 PM
Post #2


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411
myCENTs:84.36



I have the solution for you - infact I've done the exact same thing with more than 15 textfields in a screen and a save/update button - which gets enabled only when all fields are validated properly. But you gotta gimme time till tomorrow morn. It's 2am here and am almost dozing off on my keyboard. So just hold your breath for another 7-8hours wink.gif

Regards,
m^e
Go to the top of the page
 
+Quote Post
mastercomputers
post Aug 21 2005, 09:21 AM
Post #3


PESTICIDAL MANIAC
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



I'm still holding my breath in anticipation tongue.gif

I've read things like Control Arrays, but whether this has anything to do with it, I am not sure.

Basically I want a similar effect to an OK/Apply like dialog, in which if data is changed it will enable the Apply button, but I want an effect where if all the requirements are met then it will enable the button.

If it requires Control Arrays and this indexing method, then I guess that's the method I might test, but still please provide anything you have, because it sounds like your 15 textboxes compared to my 11 textboxes is what I'm after. The 2 textboxes above was just a small part of describing the problem.


Cheers,


MC
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Aug 22 2005, 01:36 AM
Post #4


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411
myCENTs:84.36



Ok here goes - there are two approaches. The first one is a little easier but lame which happens to be with control arrays. I guess you know the basic idea of control arrays - you simply copy-paste a single textbox 11 times and they will be put into a virtual array where you can refer to each textbox using its array index.

Now all the textboxes (rather most of the vb controls) have an associated event called LostFocus (along with another one named GotFocus). You need to create a skeleton procedure with the lostfocus event. Whenever the cursor leaves a textbox it'll jump to this routine. But here comes the lame part. Supposing all your textboxes have different validation routines for different types of data. You got to manually check each textbox everyone one of them looses focus and enable/disable the button accordingly. With a few textboxes this is fine - but in a screen with a large number of boxes - imagine the amount of cpu cycle this eats up.. on slower systems, you'll notice the a considerable lag before the button is enabled. But unfortunately in vb6 this is the only way to do it - since it doesn't support OOP.

However, if you're using vb.net - then the solution can be far more elegant. You can, infact, derive a subclass from the textbox control and attach a validation routine to it inside the class. This way - whenever you try to leave a textbox and the data is incorrect, the cursor is immediately placed back into the textbox with the gotfocus event. Additionaly - you can keep a counter which increases/decreases by 1 whenever a textbox is validated or has invalid data. After lostfocus, you can throw an event which then checks this counter - say if it stands at 11, then the button is enabled else - it remains disabled.

I dunno if I could clearly explain - but if you need examples, I'll be happy to provide for both of them. I'd rather go for the second one, but your project might limit you to vb6. In that case solution 1 is the only way to go.

Regards,
m^e

P.S. - about OK/Apply buttons - you'll notice that the button is enabled as soon as some data is changed in one of the fields. it really doesn't check whether the data is valid or not. Validation is done only after you press OK. That way the validation cycle happens ONLY ONCE when you press the button and not EVERYTIME the textboxes loose focus.
Go to the top of the page
 
+Quote Post
iGuest
post Nov 23 2007, 01:39 PM
Post #5


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



I suggest you to use separate function for validation which return True/False value which you can furture use on controls validation method.

In these function you have to write each validation for control, after this just select appropriate control by 'active control' then passed control array index key to 'select case' and you get appropriate code of selected text box.

Hope I can explain clearly, If you need code for this feel free to contact.

Bye.. Have a nice day.. KING

-King
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Delphi - Tfilestream(1)
  2. Force Object To Load Last(2)
  3. Question About Embedding Flash Object Header(2)
  4. Need Help With Javascript Form Validation(2)
  5. Garmon's Javascript #1 - Simple Object Database(1)
  6. Photoshop Tutorial: Selective Coloring - Color Object In A B & W Photo(5)
  7. Embedding Object In MySQL(2)
  8. PHP Tutorial: Form Verification And Simple Validation(12)
  9. Ruby - Better Programming Language Than Java Or C#?(1)
  10. How Do I Do Script Checking & Validation In PHP?(17)
  11. A Simple Checking & Validation PHP Script(6)
  12. Object & Classes Trouble(2)
  13. Datasource Object Limitations?(0)
  14. VB 6.0 Ole DB Object/Session Error(1)
  15. MS Access Validation Rule(2)
  1. OSCommerce Errors(5)
  2. Linking An Object Tag(0)
  3. Problem With Xhtml Validation(6)
  4. Simple User Validation Script(5)
  5. Php - Object Oriented Programming(1)
  6. Xhtml Validation With Php In Cgi Mode(0)
  7. C# Tutorial : Lesson 4 - Object Oriented Programming(2)
  8. Problem In Theme Or Active Object!(4)
  9. Cleanly Killing The Itunes Com Object(2)
  10. Crt Monitor Puzzler. Help Appreciated(12)
  11. Changing Path Of Shared Object(2)
  12. How To Validate The Login Form Using Php Pcre(0)
  13. Php Iteration - Object Overloading(1)


 



- Lo-Fi Version Time is now: 2nd December 2008 - 01:22 AM