楼主是什么意思,长度比较,还是逐个ASC码比较?如果是后者的话,就: '返回0时一样大,返回1时str1>str2,2时str2>str1 Private function Equal(str1$,str2$) As Integer if str1=str2 then Equal=0 : Exit function Dim len1%,len2%,i%,len% len1=Len(str1) len2=Len(str2) if len1>len2 then len = len2 else len = len1 end if For i = 0 to len if asc(mid(str1,i+1,1)) > asc(mid(str2,i+1,1)) then Equal=1 : Exit function elseif asc(mid(str1,i+1,1)) < asc(mid(str2,i+1,1)) then Equal=2 : Exit function end if next
'到这里表示Len长度字符串相等 if len=len1 then Equal = 2 '表示str2比str1长,str2大 else Equal = 1 end if End Function就这样,还可以再优化一下,楼主别忘记给分哦!
先比较第一个字符,如果第一个相等,就比较第2个, 在以后.....
'返回0时一样大,返回1时str1>str2,2时str2>str1
Private function Equal(str1$,str2$) As Integer
if str1=str2 then Equal=0 : Exit function Dim len1%,len2%,i%,len%
len1=Len(str1)
len2=Len(str2)
if len1>len2 then
len = len2
else
len = len1
end if For i = 0 to len
if asc(mid(str1,i+1,1)) > asc(mid(str2,i+1,1)) then
Equal=1 : Exit function
elseif asc(mid(str1,i+1,1)) < asc(mid(str2,i+1,1)) then
Equal=2 : Exit function
end if
next
'到这里表示Len长度字符串相等
if len=len1 then
Equal = 2 '表示str2比str1长,str2大
else
Equal = 1
end if
End Function就这样,还可以再优化一下,楼主别忘记给分哦!
vbTextCompare 可以3中选择,
如果str00 > str 01 返回1,相等返回0,小于返回-1