Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 05-05-2004, 07:46 AM   #1 (permalink)
Addict
 
Location: Grey Britain
[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?
__________________
"No one was behaving from very Buddhist motives. Then, thought Pigsy, he was hardly a Buddha, nor was he a monkey. Presently, he was a pig spirit changed into a little girl pretending to be a little boy to be offered to a water monster. It was all very simple to a pig spirit."
John Henry is offline  
Old 05-05-2004, 10:20 AM   #2 (permalink)
Banned from being Banned
 
Location: Donkey
Assuming all your textboxes are prefixed with "txt", you could try something like:

Code:
    Dim e As Control
    
    For Each e In Me.Controls
        If (TypeOf e Is TextBox) Then
            MsgBox e.Name + " = " + e.Text
        End If
    Next
I haven't used VB in a while, so I don't remember if there's a way to check the type of a control... like "if e is TextBox" (which you can do in .net)

[edit]

NM, Just remembered it. Code above edited for TypeOf
__________________
I love lamp.

Last edited by Stompy; 05-05-2004 at 10:24 AM..
Stompy is offline  
Old 05-06-2004, 03:33 AM   #3 (permalink)
Addict
 
Location: Grey Britain
Excellent. Cheers
__________________
"No one was behaving from very Buddhist motives. Then, thought Pigsy, he was hardly a Buddha, nor was he a monkey. Presently, he was a pig spirit changed into a little girl pretending to be a little boy to be offered to a water monster. It was all very simple to a pig spirit."
John Henry is offline  
Old 05-06-2004, 11:44 AM   #4 (permalink)
Crazy
 
AxelF's Avatar
 
Location: Europe
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
__________________
Coffee
AxelF is offline  
 

Tags
basic, form, looping, objects, visual


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 05:52 AM.

Tilted Forum Project

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76