vb6 call form with name contained in array

左心房为你撑大大i 提交于 2019-12-02 06:52:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!