Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variant data type usage

Status
Not open for further replies.

iainm

Technical User
Nov 28, 2001
67
AU
I've got a subprocedure which has as inputs a target form, field and data. The procedure opens the target form, goes to the target control and finds the first instance of the target data. Using this I can link between different forms so that the same data comes up in each form. Sometimes this data is an integer and sometimes it is a string. The obvious solution is variant data type. My problem is that I have no way of knowing how VB recognises the difference if the data type is variant. One possible way I thought of for overcoming this is to also pass a variable which gives the type, and copy the variant into different data types depending on this argument. This seemed to work ok, but I've realised that it makes for really scrappy code, and doesn't do much for reusability (which this procedure should have). I suppose what I'm after is a gurantee that if I put an int in a var and pass it to my procedure, then search on an int field with the var it will come up with the right data, and the same for string. Can anyone confirm or deny?
-IainM
 
bump
come on, guys, yes or no will do
 
erm....Okay, maybe yes or no won't do. No it won't work, or no it won't be a problem?
 
Okay, through some fairly complicated and risky trial and error with my database I managed to find the answer for myself. For anyone who's concerned, the variant type works quite well.
 
beware of the variant data type and untrapped date assignments
 
okay, noted. Are dates the only thing it has issues with? I'm only using int and str in this database so it shouldn't be a problem. Is there another workaround for dates?
 
I can see how that would screw you. thanks mate.
 
My pleasure! Made this mistake in a large VB app. Blew 'bad programmer' droppings all over my user's screen. Not a pretty sight!

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top