问题
I have an Array named Menus. It contains a form name per element.
How can I call them dynamically?
For example, if Menus(1) = "Login", and Menus(2) = "Logout" I need to say
Login.Show
but I want to do this using the Array name. I clearly can't do this:
Menus(X).Show
Is this possible in VB or is there a way around this?
Thanks in advance!
回答1:
What you're essentially trying to do is use a form's name to instantiate and load a form.
One way to do this is to pass a string with your form's name to the Form Collection
's Add
function:
Dim f As Form
Set f = Forms.Add(Menus(X))
f.Show
Or, using VB6's CallByName Function:
Dim f As Form
Set f = CallByName(Forms, "Add", VbMethod, Menus(X))
f.Show
回答2:
You can use the following code:
Form form = Menus[x] as Form
Form.show
来源:https://stackoverflow.com/questions/8692147/vb6-call-form-with-name-contained-in-array