Link to home
Start Free TrialLog in
Avatar of cbutton
cbuttonFlag for United States of America

asked on

Calculating a control name

I want to be able to construct the name of a control based on a calculation. Let's say I have a bunch of text controls, e.g., txtA1, txtA2, . . ., txtA15. Based on a calculation I want to be able to say:

txtA<n>.Text = (expression),

where <n> is any number from 1 to 15.
Right now I do it with a bunch of If and ElseIf statements, but I am looking for a way to construct the left-hand side of the statement above instead.

Avatar of Neal Hartman
Neal Hartman
Flag of United States of America image

Use a control array

txt(1).text
txt(2).text
etc...

ASKER CERTIFIED SOLUTION
Avatar of ameba
ameba
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of caraf_g
caraf_g

Dang, ameba, you're too quick :-)

cbutton, ameba has the right solution for you!
Yes, you are slow :)
Avatar of cbutton

ASKER

Thanks, ameba. It works just the way you said it would.

By the way, I don't really understand "Me."
Thanks for your points.

'Me' represents current form instance in the sample.
Another sample:
To close a form, use
   Unload Me
"Unload Me"
Yes - but only if you're inside a form's code module. To clarify:

Let's say you have a project with two forms, Form1 and Form2 and an ordinary basic module Module1

Inside the code module for Form1, Unload Me unloads Form1
Inside the code module for Form2, Unload Me unloads Form2
Inside Module1... Module1 is not the code module for a form, so Unload Me is not allowed.

PS - if you're working with multiple instances of a form, Unload Me unloads the current instance. If not, ignore this PS.
Thanks for clarification.