标题:split函数的问题
只看楼主
wwzzqq
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-1
 问题点数:0 回复次数:1 
split函数的问题

各位高手好,小弟刚接触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

搜索更多相关主题的帖子: split 函数 check Then 
2007-07-04 21:49
StartMe
Rank: 2
等 级:论坛游民
帖 子:34
专家分:42
注 册:2006-10-15
得分:0 

没太细看你的程序,不过你可用ubound(b)判断b的上界,以便程序中能更好处理,就不会出现超界情况。

2007-07-04 23:24



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-152791-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018265 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved