Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

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?
0
Rusch
Asked:
Rusch
  • 2
  • 2
  • 2
  • +5
2 Solutions
 
RuschAuthor Commented:
i feel stupid, but i really need to know fast..
0
 
NPluisCommented:
I'm not quite sure what you want to do. IS NameArray an array of controls on your form and you want to hide them but then?

Could you rephrase your question?
0
 
e-DiddyCommented:
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
JMoon5FTMCommented:
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.
0
 
jayeshshahCommented:
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
0
 
e-DiddyCommented:
jayeshshah--
 I think you can emulate the eval method in VB by using the CallByName function.
0
 
RuschAuthor Commented:
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.
0
 
RMatzkaCommented:
Create the frames as an array of frames. I.e., all your frames have the same Name property (e.g. "FrameArray") and only differ by their Index property. Then the following code works:

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

If, on the other hand, you need to distinguish forms by their meaning, declare an enum type, like this:
Private Enum FrameName
  WelcomeForm
  AddForm
  AlterForm
  DelForm
  ViewRecordsForm
  ViewStatsForm
  ProgSettingsForm
End Enum
Then you can write code like
FrameArray(DelForm).Visible=True
0
 
NPluisCommented:
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

0
 
CleanupPingCommented:
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?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Split points between: NPluis and RMatzka

DanRollins -- EE database cleanup volunteer
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now