首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

CallByName 中的Check有关问题

2012-01-28 
CallByName 中的Check问题新建标准 EXE 工程 添加 Check1, Check2, Check3 添加 Command1, Text1 Set.t

CallByName 中的Check问题
新建标准 EXE 工程
' 添加 Check1, Check2, Check3
' 添加 Command1, Text1
' Set.txt 中的内容:
'Check1=1
'Check2=0
'Check3=2
'Command1=按钮文本
'Text1=运行时改变控件属性!
Option Explicit

Private Sub Command1_Click()

  '下面文件路径按你实际情况写
  '请保证格式正确
  Open "X:\Temp\Set.txt" For Input As #1
  Dim strText$, arrParam$()
  While (Not EOF(1))
  Line Input #1, strText
  arrParam = Split(strText, "=")
  If (InStr(1, arrParam(0), "Command") = 1) Then
  CallByName Controls(arrParam(0)), "Caption", VbLet, arrParam(1)
  Else
  If (InStr(1, arrParam(0), "Text") = 1) Then
  CallByName Controls(arrParam(0)), "Text", VbLet, arrParam(1)
  Else
  CallByName Controls(arrParam(0)), "Value", VbLet, arrParam(1)
  End If
  End If
  Wend

End Sub

如果把CHECK改变成数组 就提示控件未找到 求解决办法

[解决办法]

VB code
Option Explicit' Check1 是控件数,共人3个成员,索引号(创建时的默认值)分别是0, 1, 2' Set.txt 中的内容:'Check1,0=1'Check1,1=0'Check1,2=2'Command1=按钮文本'Text1=运行时改变控件属性!Private Sub Command1_Click()    '下面文件路径按你实际情况写,请保证格式正确!    Open "X:\Temp\Set.txt" For Input As #1    Dim strText$, arrParam$()    While (Not EOF(1))        Line Input #1, strText        arrParam = Split(strText, "=")        If (InStr(1, arrParam(0), "Command") = 1) Then            CallByName Controls(arrParam(0)), "Caption", VbLet, arrParam(1)        Else            If (InStr(1, arrParam(0), "Text") = 1) Then                CallByName Controls(arrParam(0)), "Text", VbLet, arrParam(1)            Else                CallByName Controls((Split(arrParam(0), ",")(0)))(Split(arrParam(0), ",")(1)), "Value", VbLet, arrParam(1)            End If        End If    Wend    CloseEnd Sub 

热点排行