当前位置:编程学习 > C#/ASP.NET >>

VB动态添加文本框出错(VBA转出错)

Sub AddRow()
    Dim i As Integer
    Dim myTextBox As MSForms.TextBox
    Dim ArrAlign
   ' If n = 15 Then Exit Sub         '最多是15行
    

    
    n = n + 1
    ArrAlign = Array(2, 2, 3, 3, 3, 2, 3, 3, 3, 3) 'array数组为了规范文本框的对齐方式【TextBox.TextAlign】
    
    With 增加文本框  '这里+【= .Controls("Frame2")】+【End With】能让文本框放到Forms里
    
    With 增加文本框
        For i = 1 To 10
            cn = cn + 1
            Set MyText(cn) = New Text_Count
            Set myTextBox = Me.Controls.Add("Forms.TextBox.1", "Text(" & n & "," & i & ")", True) '这句话显示类型不匹配
            Text_Number.Text = myTextBox.Name
              With myTextBox
                .SpecialEffect = 6
                .Width = ArrWidth(i)
                .TextAlign = ArrAlign(i - 1)
                .Top = 1
                .Left = L
                .Top = T
                .Text = 1 '文本框赋值,初始化
                L = L + .Width
                
              End With
            MyText(cn).Attech myTextBox
            
        Next
        .Controls("Text(" & n & ",1)").Text = n          '第一个文本框自动输入行号[=DATE则自动输入日期]
        .Controls("Text(" & n & ",3)").SetFocus             '1代表选中第一个文本框
    End With
    L = -2
    T = T + 18
    End With
End Sub --------------------编程问答-------------------- 跪求高手 --------------------编程问答-------------------- 是vba 还是vb6,还是vb.net 
各种添加方法是不一样的哦。 --------------------编程问答-------------------- 我想改成VB6 --------------------编程问答-------------------- 自力更生丰衣足食

Sub AddRow()
    Dim i As Integer
    Dim myTextBox As TextBox
    Dim ArrAlign
   ' If n = 15 Then Exit Sub         '最多是15行
    
    If n > 9 Then
           Frame3.Height = Frame3.Height + 300
           Frame3.Top = Frame3.Top - 300
   End If
    
    
    n = n + 1
    ArrAlign = Array(0, 1, 1, 2, 2, 2, 2, 2, 2, 2) 'array数组为了规范文本框的对齐方式【TextBox.TextAlign】
    
    With 增加文本框  '这里+【= .Controls("Frame2")】+【End With】能让文本框放到Forms里
    
    With 增加文本框
        For i = 0 To 9
            
            Set MyText(cn) = New Text_Count
            Set myTextBox = Controls.Add("VB.TextBox", "Tex" & n & i & "l", Me.Frame3)  '创建文本框并设置其属性
        
              With myTextBox
                '.SpecialEffect = 6
                .Appearance = 0
                '.BorderStyle = 0
                .Width = ArrWidth(i)
                If n Mod 2 = 0 Then .BackColor = &H8000000F
              '  .FontUnderline = True
                '.ForeColor = &HFF&
                .Alignment = ArrAlign(i)
                .Height = 300
                .Top = 400
                .Left = L
                .Top = T
                .Text = 1 '文本框赋值,初始化
                L = L + .Width
                .Visible = True
              End With
            MyText(cn).Attech myTextBox
              '  Load Text(i)
   '     MsgBox myTextBox.Name
    cn = cn + 1
        If Mid(myTextBox.Name, InStr(1, myTextBox.Name, "l") - 1, 1) = 0 Then
            myTextBox.Text = n
            myTextBox.BackColor = &HFFC0C0
        End If
        If Mid(myTextBox.Name, InStr(1, myTextBox.Name, "l") - 1, 1) = 9 Then
            myTextBox.Text = "公司"
           ' myTextBox.BackColor = &HFFC0C0
        End If
      'Mid(Str, InStr(1, Str, "x") + 1, InStr(1, Str, "l") - InStr(1, Str, "x") - 2)
      'MID("tEX1l",6,1)
      
     ' MID("tEXT(12,1)",6,1)
        Next
        
       ' Right(AnyString, 1)
'        .Controls("Text(" & n & ",1)").Text = n          '第一个文本框自动输入行号[=DATE则自动输入日期]
      '  .Controls("Text(" & n & ",3)").SetFocus             '1代表选中第一个文本框
   '   Text_Number.Text = cn
    End With
    L = 0
    T = T + 300
    End With
    Call bg
End Sub
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,