没看懂你要干什么,只是觉得这段代码没什么问题,但执行起来效率有点问题。
If (Mid(c, j, 1) = "零") Then
i = i + 0
ElseIf (Mid(c, j, 1) = "0") Then
i = i * 10
ElseIf (Mid(c, j, 1) = "一" Or Mid(c, j, 1) = "1") Then
i = i + 1
ElseIf (Mid(c, j, 1) = "二" Or Mid(c, j, 1) = "2") Then
i = i + 2
ElseIf (Mid(c, j, 1) = "三" Or Mid(c, j, 1) = "3") Then
i = i + 3
ElseIf (Mid(c, j, 1) = "四" Or Mid(c, j, 1) = "4") Then
i = i + 4
ElseIf (Mid(c, j, 1) = "五" Or Mid(c, j, 1) = "5") Then
i = i + 5
ElseIf (Mid(c, j, 1) = "六" Or Mid(c, j, 1) = "6") Then
i = i + 6
ElseIf (Mid(c, j, 1) = "七" Or Mid(c, j, 1) = "7") Then
i = i + 7
ElseIf (Mid(c, j, 1) = "八" Or Mid(c, j, 1) = "8") Then
i = i + 8
ElseIf (Mid(c, j, 1) = "九" Or Mid(c, j, 1) = "9") Then
i = i + 9
ElseIf (Mid(c, j, 1) = "十") Then
i = i * 10
ElseIf (Mid(c, j, 1) = "百") Then
i = i * 10
ElseIf (Mid(c, j, 1) = "卷") Then
i = i
Else: x = False
End If
这一堆代码改成:
前面再定义一个变量:
dim cd as string
程序代码:
cd = Mid(c, j, 1)
Select Case cd
Case "零", "卷"
i = i + 0
Case "0", "十", "百"
i = i * 10
Case "一", "1"
i = i + 1
Case "二", "2"
i = i + 2
Case "三", "3"
i = i + 3
Case "四", "4"
i = i + 4
Case "五", "5"
i = i + 5
Case "六", "6"
i = i + 6
Case "七", "7"
i = i + 7
Case "八", "8"
i = i + 8
Case "九", "9"
i = i + 9
Case Else
x = False
End Select