假如我有5个textbox,我要分别显示1,2,3,4,5 (string)tb1.text = "1"
tb2.text = "2"
tb3.text = "3"
tb4.text = "4"
tb5.text = "5"能用一个loop解决战斗不?

解决方案 »

  1.   

    '将text设置为数组
    for i=1 to 5
        text(i).text=i
    next i
      

  2.   

    Dim ocontrol As Control
    For Each ocontrol In Me.Controls
    If LCase(TypeName(ocontrol)) = "textbox" Then
    If ocontrol.Name = "Text1" Then
        ocontrol.Text = "aaa"
        End If
    End If
    Next
      

  3.   

    如果你的textbox控件如你示例的那样都有序号的话:dim i  aslong
    for i=1 to 5
        me("tb" & i).text =i
    next
      

  4.   

    如果你的textbox控件名称,如你示例的那样都有序号的话:dim i as long
    for i=1 to 5
        me("tb" & i).text =i
    next
      

  5.   


        Dim ocontrol As Control
        For Each ocontrol In Me.Controls
            If LCase(TypeName(ocontrol)) = "textbox" Then
             ' ocontrol.Text = ocontrol.Tag '需要在textbox的tag写上1 2 3
               ocontrol.Text = Right(ocontrol.Name, Len(ocontrol.Name) - Len("Text")) '假设控件名是TextX类型
                '最好还是用控件数组
            End If
        Next
      

  6.   

    也可以用这种方法:
    dim i as long
    for i=1 to 5
        Controls("tb" & i).text =i
    next参考:
    http://tieba.baidu.com/f?kz=1016288544