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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specify object names with variables

Status
Not open for further replies.

Fion

Vendor
Sep 25, 2003
50
0
0
US
Hi, I am tring to consolidate some code in a program I am writing, and I'm hoping what I want to do is possible...

I have sets of objects (text and comboboxes in a frame) and each object in the sets have the same name, but for the last number. For example:

Condition1: (a frame)
Con1.text (a combobox)
eq1.txt (a combobox)

Condition2: (a frame)
Con2.text (a combobox)
eq2.txt (a combobox)

Condition1: (a frame)
Con1.text (a combobox)
eq1.txt (a combobox)

Condition3: (a frame)
Con3.text (a combobox)
eq3.txt (a combobox)

In frame, the only difference between each name is the number at the end. What I want to do is be able to make a single sub that will work for each on them, by changing a variable. Below is how it would work (I know the coding I have here is wrong, but this is the idea.) I'm hoping someone will bae able to tell me how I can actually make this work.

Function Check(X as integer) as string
check = Con(X).text + eq(X).text
End function

Do you see what I am attempting here? I want to be able to call any of my text or comboboxes by changing only 1 variable, the X. Is this possible?
Thanks!

Fion
 
Do a search for control array.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Use a control array. Give all the controls in the set the same name and set their index values to 0,1,2 etc. When you look at their event procedures you will now find an Index value referred programmatically:

Private Sub cboMain_Click(Index As Integer)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

Essex Steam UK for steam enthusiasts
 
excellent, thank you! That is exactly what I needed
 
Sorry DJJ - I type slower!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

Essex Steam UK for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top