Gao57 2022-11-20 17:52 采纳率: 76.9%
浏览 2
已结题

vb根据文本内容控制按钮显示

有一个文本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

  • 写回答

1条回答 默认 最新

  • 浪客 2022-11-20 23:49
    关注
    
    
    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
    
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月29日
  • 已采纳回答 11月21日
  • 创建了问题 11月20日

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上