vb6 调用形式,名称包含在数组中

发布于 2024-12-23 10:15:51 字数 307 浏览 5 评论 0原文

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

我怎样才能动态地调用它们?

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

Login.Show

但我想使用数组名称来做到这一点。我显然不能这样做:

Menus(X).Show

这在 VB 中可能吗?或者有办法解决这个问题吗?

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国际总奸 2024-12-30 10:15:51

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

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

Dim f As Form
Set f = Forms.Add(Menus(X))
f.Show

或者,使用 VB6 的 CallByName 功能:

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

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
初心 2024-12-30 10:15:51

您可以使用以下代码:

Form form = Menus[x] as Form 
Form.show

You can use the following code:

Form form = Menus[x] as Form 
Form.show
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文