各位高手好,小弟刚接触VB,遇到了split()函数的数组问题,我用split()分开text1的字符,但是这个字符的长度是不一定的(比如 n01 g02 g03 x88是正确的,n01 g02 x88也是正确的),所以在定义数值的时候,容易出现下标越界的情况,请高手看看这个问题怎么解决
Private Sub Text1_DblClick()
Dim a As String
a = Text1.Text
b = Split(a, " ")
If check_b1(b) = 1 Then
If check_b2(b) = 1 Or check_b2(b) = 2 Then
Text2.Text = UCase(a)
Else
Text2.Text = "程序错误2"
End If
Else
Text2.Text = "程序错误1"
End If
End Sub
Function check_b1(b As Variant) As Integer
c11 = Left(b(1), 1)
d12 = Mid(b(1), 2, 2)
m1 = Len(b(1))
If m1 = 3 And d12 < 100 And d12 >= 0 And c11 = "g" Or c11 = "m" Or c11 = "t" Then
check_b1 = 1
Else0
check_b1 = 0
End If
End Function
Function check_b2(b As Variant) As Integer
c11 = Left(b(1), 1)
d12 = Mid(b(1), 2, 2)
m1 = Len(b(1))
c21 = Left(b(2), 1)
m2 = Len(b(2))
d22 = Mid(b(2), 2, m2 - 1)
c31 = Left(b(3), 1)
If d22 > 0 And d22 < 100 And m2 = 3 And d22 <> d12 And c21 = "g" Or c21 = "m" Or c21 = "t" Then
check_b2 = 1
ElseIf d22 < 1000 And d22 > -1000 And m2 >= 3 And c21 = "x" Or c21 = "y" Then
check_b2 = 2
Else
check_b2 = 0
End If
End Function