VB中的问题,关于控件数组

来源:百度知道 编辑:UC知道 时间:2024/05/13 10:40:39
这是这个按钮的代码
Private Sub Command21_Click(Index As Integer)
Shell "cmd.exe"
End Sub

按钮在主窗体里面(按钮在Frame里面)我打开程序,自动运行CMD
点按钮也可以运行.

后来我把控件去掉,重新弄个按钮.
Private Sub Command7_Click()
Shell "cmd.exe", vbNormalFocus
End Sub

这时候却不会自动运行CMD,点按钮可以运行.

为什么控件中的按钮会自动运行CMD?
把其他的代码输入进去,也是不点按钮自动运行.
这是为什么?有什么方法可以不让他自动运行,只在点他的时候才运行?
主窗体的代码:
Private Sub Form_Load()
Dim soft_ads(10) As String
Dim game_ads(10) As String
Dim soft_caption(10) As Integer
Dim game_caption(10) As Integer
Dim num As Integer
Dim mc As Integer
Dim tx(9) As String

Open "soft.txt" For Input As #1
Do While Not EOF(1)
Input #1, mc
For num = 0 To (mc - 1)
Input #1, tx(num)
Next num
For num = 0 To 9
If num > (mc - 1) Then Command21(num).Visible = False Else Command21(num) = True
Next num
For num = 0 To (mc - 1)
Command21(n

明白了,LZ:

注意到你的 Do...Loop 里的 Command21(num) = True 了吗?这代表让 Command21(num) 被按下,所以每次执行到这里并不是设置显示与否,而是运行 Command21_Click ……

你明显把 .Visible 漏掉了,唉,可恶的默认属性……
============================================================
cmd的路径用不着写全,因为它在Windows目录下……

试了一下,没有你说的状况。

你可能在窗体的启动Form_Load什么的里面写了点什么调用了Command21

Shell "cmd.exe" ,要么程序的路径写全,如: shell "c:\windows\cmd.exe"