所以我试图找出为什么我的Visual Basic代码无法正常工作,我试图让它成为一个合并的方式有两个文本框,因为我需要它们分开为他们旁边的文本和我我将使用一个变量来简化这个,但是当我输入代码它似乎不起作用时,当我从第二个中删除.Text并且当我添加时,它会出现BC30452错误。文本到两者都没有错误,直到启动。
代码:
Dim Night1 = N1Output And "-" And N1
Dim Night2 = N2Output And "-" And N2
Dim Night3 = N3Output And "-" And N3
Dim Night4 = N4Output And "-" And N4
Dim Night5 = N5Output And "-" And N5
Dim Night6 = N6Output And "-" And N6
Dim Night7 = N7Output And "-" And N7
Dim Night8 = N8Output And "-" And N8
Dim Night9 = N9Output And "-" And N9
Dim Night10 = N10Output And "-" And N10
Dim Night11 = N11Output And "-" And N11
Dim Night12 = N12Output And "-" And N12
Dim Night13 = N13Output And "-" And N13
Dim Night14 = N14Output And "-" And N14
Dim Night15 = N15Output And "-" And N15
我将.Text添加到它们的末尾并且它没有初始错误,但是在启动时,如果我使用按钮打开代码所在的表单,它将无法工作。 N1,N2和输出是文本框
答案 0 :(得分:0)
您可以使用Night
数组,只需遍历所有User_Form Textboxes
,并为每一对填充Night(i)
。
示例,对于For i = 1 To 15
内的第3个循环,它将采用名为" N3Output"的User_Form控件的值。添加" - "然后是来自" N3"的值(文本);并将数组放在Night(3)
元素内。
尝试以下代码(应位于User_Form
模块中):
Private Sub MergeTextBoxes()
Dim Night() As String
Dim i As Long
ReDim Night(1 To 15) '<-- redim Night array size to 15 (according to your example)
For i = 1 To 15
Night(i) = Me.Controls("N" & i & "Output").Value & "-" & Me.Controls("N" & i).Value '<-- add values to all 15 array elements from User_From textboxes
Next i
End Sub