![]() |
[Visual Basic 6] Looping through form objects.
I'm writing a program that takes data from a load of textboxes on a form and puts them in a database. I know about the With command and I figure there must be some way to loop through all the textboxes on a particular form rather than having to cut and paste instructions for each one.
Can't find anything in the documentation/Google/Experts-Exchange etc. as I don't really know what I'm looking for. Any ideas? |
Assuming all your textboxes are prefixed with "txt", you could try something like:
Code:
Dim e As Control [edit] NM, Just remembered it. Code above edited for TypeOf |
Excellent. Cheers
|
Just name them the same and they will be a collection. Then you access them using their index. Having 4 boxes they will be indexed 0-3. Like txtPlants(1) for the second one.
( It looks best in the code if you define global constants naming them: cTrees = 0 cFlowers = 1 etc. Then reference them like this: txtPlants(cTrees) ) They will share the same code with the index passed into the sub if you have some code on Click for example. By doing this you can loop through them like: for i = 0 to 4 ' your code here using this kind of reference: txtPlants(i) next i |
All times are GMT -8. The time now is 11:51 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project