有一个文本ok.txt
里面内容
1.txt
2.txt
3.txt
vb循环读出判断是否有这个文本,
如果有commad就可以点击,如果没有就显示灰色
我想用循环变量来控制commad
ok内容不固定,commad数量不固定
commad根据ok.txt内容多少自动变量
比如ok.txt第一行,
对应1.txt,可以设置
s=s+1
commad & s ,也就是commad1
有一个文本ok.txt
里面内容
1.txt
2.txt
3.txt
vb循环读出判断是否有这个文本,
如果有commad就可以点击,如果没有就显示灰色
我想用循环变量来控制commad
ok内容不固定,commad数量不固定
commad根据ok.txt内容多少自动变量
比如ok.txt第一行,
对应1.txt,可以设置
s=s+1
commad & s ,也就是commad1
Dim btn() As VB.CommandButton
Private Sub Form_Load()
size = 0
End Sub
Private Sub Command1_Click()
allfile = ""
sbuf = ""
size = 0
Open App.Path & "\ok.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, sbuf
If Len(sbuf) = 0 Then Exit Do
size = size + 1
allfile = allfile & sbuf & ","
Loop
Close #1
'根据读入条数更改数组大小
size = size - 1
ReDim btn(size) As VB.CommandButton
sa = Split(allfile, ",")
t = 50
l = 0
For i = 0 To size
has = Dir(App.Path & "\" & sa(i)) <> ""
Set btn(i) = Controls.Add("VB.CommandButton", "cmd" & i)
If l = 10 Then
t = t + 500
l = 0
End If
With btn(i)
.Enabled = has
.Tag = sa(i)
.Left = l * (.Width + 300)
.Top = t
.Caption = i + 1 & ":" & sa(i)
.Visible = True
End With
l = l + 1
Next i
End Sub