vb6调用表单,名称包含在数组中 [英] vb6 call form with name contained in array

查看:136
本文介绍了vb6调用表单,名称包含在数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Menus的数组.它包含每个元素的表单名称.

I have an Array named Menus. It contains a form name per element.

如何动态调用它们?

例如,如果 Menus(1)="Login" ,而 Menus(2)="Logout" ,我要说

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

在VB中有可能吗?

提前谢谢!

推荐答案

您本质上想做的就是使用表单名称来实例化并加载表单.

What you're essentially trying to do is use a form's name to instantiate and load a form.

一种方法是将带有表单名称的字符串传递给表单CollectionAdd函数:

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

或者,使用VB6的 CallByName 函数:

Or, using VB6's CallByName Function:

Dim f As Form
Set f = CallByName(Forms, "Add", VbMethod, Menus(X))
f.Show

这篇关于vb6调用表单,名称包含在数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆