Link to home
Start Free TrialLog in
Avatar of Rusch
Rusch

asked on

evaluating an expression containing a reference to an array

For x = 1 To 7
NameArray(x).Visible = False
Next x

ok, i dunno where else to ask. how do i evaluate "namearray(x)" so that the expression evaluates proparly?
Avatar of Rusch
Rusch

ASKER

i feel stupid, but i really need to know fast..
ASKER CERTIFIED SOLUTION
Avatar of NPluis
NPluis

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
If NameArray is a valid form Array this should work. I have some of the same questions that NPluis had before but you can take this into consideration.

Try this to initialize the For

For x = 0 To NameArray.Ubound

form arrays start at 0 (default) and this will make sure you do not loop past the array

Everything else looks ok Though...if NameArray is actually a Form Array
If NameArray is a control array, the controls may not have consecutive indexes - for example, only NameArray(0), NameArray(1), and NameArray(10) may be valid.

Place On Error Resume Next before the loop and On Error Goto 0 after the loop to ignore errors caused by missing members.
this would not be possible in Visual Basic to evaluate expressions. Though it;s possible in Foxpro and Java (eval fucntion), I have not heard about it in Visual Basic.

K'Regards

Jayesh
jayeshshah--
 I think you can emulate the eval method in VB by using the CallByName function.
Avatar of Rusch

ASKER

Ok, NameArray(10) is simply an array I've filled with text strings. These strings correspond to Frames that I've created in Visual Basic. It's all in one actual Form, and what I'm trying to do is simply hide certain Frames and the display one. Since I've not been able to evaluate that one string, this is how I've solved it temporarily:

Private Sub Command1_Click()
WelcomeForm.Visible = False 'hides form
AddForm.Visible = True 'shows form
AlterForm.Visible = False 'hides form
DelForm.Visible = False 'hides form
ViewRecordsForm.Visible = False 'hides form
ViewStatsForm.Visible = False 'hides form
ProgSettingsForm.Visible = False 'hides form
Call AddARecord 'starts this menu-option
End Sub

WelcomeForm, AddForm, etc.. are my entries in NameArray(10). Ignore the *Form name I've given them, because they're not actually forms, but frames. Coming from a lot of JavaScript usage, I thought this would be a simple way of minimizing coding.

I hope this helps understand my question. Thank you.
SOLUTION
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
I think what you want is this:

for x = 0 to 7
  Me.Controls(NameArray(x)).Visible = False
next

This is to hide alle of them. To show 1 you can use Me.Controls(NameArray(x)).Visible = True

Rusch:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
Avatar of DanRollins
Moderator, my recommended disposition is:

    Split points between: NPluis and RMatzka

DanRollins -- EE database cleanup volunteer