这个vb提示最长那句类型不匹配,不知道错在哪里?

来源:百度知道 编辑:UC知道 时间:2024/06/14 11:32:30
Private Sub Command1_Click()
Dim cha As String
Dim pro(2) As Integer
Dim a, m As Integer
cha = "asd5dsasda6"
For m = 1 To Len(cha)
For i = 1 To 20
If IsNumeric(Mid(cha, m, 1)) = True And IsNumeric(Mid(m + 1, 1)) = True Then pro(i) = CInt(Mid(cha, m, 1) & Mid(m + 1, 1)) Else pro(i) = CInt(Mid(cha, m, 1))
Next i
Next m
MsgBox pro(i)
End Sub
语句If IsNumeric(Mid(cha, m, 1)) = True 是判断为数字时候才用cint()转换为integer.
这个是最后改过的结果,输出后发现不能正确的得出结果5,6,而是都为6,又是哪里的错呢?
Private Sub Command1_Click()
Dim cha As String
Dim pro(2) As String
Dim a, m As Integer
cha = "asd5dsasda6"
For m = 1 To Len(cha)
For i = 1 To 2
If IsNumeric(Mid(cha, m, 1)) = True And IsNumeric(Mid(cha, m + 1, 1)) = True Then pro(i) = Mid(cha, m, 1) & Mid(cha, m + 1, 1) Else pro(i) = Mid(cha, m, 1)
Next i
Next m

Text1.Text = pro(1)
Text2.Text = pro(2)
End Sub

CINT()?
你要求ASCII码的话就用ASC()
cint参数不能是字符型啊

Mid(m + 1, 1)和 Mid(m + 1, 1)两个地方,把字符串变量cha写掉了。补上就可以了

错在else后面的Cint(),当M=1时就变成了Cint(a)了,当然要出错