如何在vb中连续输入一些值使其与一个二维数组对应
比如说我要把1,2,3,4,5,6赋值给数组a(1,2),应该怎么写呢?不使用输入框,直接输入6个数值可以实现吗?...
比如说我要把1,2,3,4,5,6赋值给数组a(1,2),应该怎么写呢?不使用输入框,直接输入6个数值可以实现吗?
展开
展开全部
'可以实现,数值之间用“|”分隔
Private Sub Command1_Click()
Dim a(0 To 1, 0 To 2), I As Long, J As Long
Dim nStr As String, Str1 As String, S As Long, S1 As Long
nStr = "1|2|3|4|5|6"
'赋值给数组
For I = 0 To 1
For J = 0 To 2
S1 = InStr(S + 1, nStr, "|")
If S1 > 0 Then Str1 = Mid(nStr, S + 1, S1 - S - 1) Else Str1 = Mid(nStr, S + 1)
a(I, J) = Val(Str1)
S = S1
Next
Next
'显示数组的值
For I = 0 To 1
For J = 0 To 2
Me.Print a(I, J)
Next
Next
End Sub
Private Sub Command1_Click()
Dim a(0 To 1, 0 To 2), I As Long, J As Long
Dim nStr As String, Str1 As String, S As Long, S1 As Long
nStr = "1|2|3|4|5|6"
'赋值给数组
For I = 0 To 1
For J = 0 To 2
S1 = InStr(S + 1, nStr, "|")
If S1 > 0 Then Str1 = Mid(nStr, S + 1, S1 - S - 1) Else Str1 = Mid(nStr, S + 1)
a(I, J) = Val(Str1)
S = S1
Next
Next
'显示数组的值
For I = 0 To 1
For J = 0 To 2
Me.Print a(I, J)
Next
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询