关于半角和全角输入的问题。VB程序实现问题。
输入的阿拉伯数字,在半角和全角输入状态中各有什么不同?我不要什么字符所占的位数不同,我要实质的不同。最好能解释:输入“2加2等于”中,现在已经能实现半角输入状态的计算得4...
输入的阿拉伯数字,在半角和全角输入状态中各有什么不同?我不要什么字符所占的位数不同,我要实质的不同。
最好能解释:输入“2加2等于”中,现在已经能实现半角输入状态的计算得4,但不能实现全角输入状态的计算。意思是阿拉伯数字,输入时有两中输入状态。请问怎么实现全角状态的程序改动?相关程序如下:
Private Sub Form_Load()
s = "1加3等于多少,6减3等于多少,5乘3等于多少,9除3等于多少"
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.IgnoreCase = True
re.Global = True
re.Pattern = "([0-9\-]+(?:\.[0-9]+)?)([加减乘除])([0-9\-]+(?:\.[0-9]+)?)等于(.*?)"
For Each i In re.Execute(s)
Select Case i.SubMatches(1)
Case "加"
s1 = i.SubMatches(0) & "+" & i.SubMatches(2) & "=" & (Val(i.SubMatches(0)) + Val(i.SubMatches(2)))
Case "减"
s1 = i.SubMatches(0) & "-" & i.SubMatches(2) & "=" & (Val(i.SubMatches(0)) - Val(i.SubMatches(2)))
Case "乘"
s1 = i.SubMatches(0) & "*" & i.SubMatches(2) & "=" & (Val(i.SubMatches(0)) * Val(i.SubMatches(2)))
Case "除"
s1 = i.SubMatches(0) & "/" & i.SubMatches(2) & "=" & (Val(i.SubMatches(0)) / Val(i.SubMatches(2)))
End Select
MsgBox s1
Next i
End Sub 展开
最好能解释:输入“2加2等于”中,现在已经能实现半角输入状态的计算得4,但不能实现全角输入状态的计算。意思是阿拉伯数字,输入时有两中输入状态。请问怎么实现全角状态的程序改动?相关程序如下:
Private Sub Form_Load()
s = "1加3等于多少,6减3等于多少,5乘3等于多少,9除3等于多少"
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.IgnoreCase = True
re.Global = True
re.Pattern = "([0-9\-]+(?:\.[0-9]+)?)([加减乘除])([0-9\-]+(?:\.[0-9]+)?)等于(.*?)"
For Each i In re.Execute(s)
Select Case i.SubMatches(1)
Case "加"
s1 = i.SubMatches(0) & "+" & i.SubMatches(2) & "=" & (Val(i.SubMatches(0)) + Val(i.SubMatches(2)))
Case "减"
s1 = i.SubMatches(0) & "-" & i.SubMatches(2) & "=" & (Val(i.SubMatches(0)) - Val(i.SubMatches(2)))
Case "乘"
s1 = i.SubMatches(0) & "*" & i.SubMatches(2) & "=" & (Val(i.SubMatches(0)) * Val(i.SubMatches(2)))
Case "除"
s1 = i.SubMatches(0) & "/" & i.SubMatches(2) & "=" & (Val(i.SubMatches(0)) / Val(i.SubMatches(2)))
End Select
MsgBox s1
Next i
End Sub 展开
1个回答
展开全部
百度自动做全角转换了
你把代码里的四个[0-90-9]中后面的0和9改成全角
s = "6加3等于多少,6减3等于多少,5乘3等于多少,9除3等于多少"
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.IgnoreCase = True
re.Global = True
re.Pattern = "-?([0-90-9]+(?:\.[0-90-9]+)?)([加减乘除])(-?[0-90-9]+(?:\.[0-90-9]+)?)等于(.*?),?"
Dim arr(1) As Double
For Each i In re.Execute(s)
For j = 0 To 2 Step 2
s = i.SubMatches(j)
For k = 1 To Len(s)
If Asc(Mid(s, k, 1)) < 0 Then Mid(s, k, 1) = Chr(Asc(Mid(s, k, 1)) + 23680)
Next k
arr(j \ 2) = Val(s)
Next j
Select Case i.SubMatches(1)
Case "加"
s1 = arr(0) & "+" & arr(1) & "=" & (arr(0) + arr(1))
Case "减"
s1 = arr(0) & "-" & arr(1) & "=" & (arr(0) - arr(1))
Case "乘"
s1 = arr(0) & "*" & arr(1) & "=" & (arr(0) * arr(1))
Case "除"
s1 = arr(0) & "/" & arr(1) & "=" & (arr(0) / arr(1))
End Select
MsgBox s1
Next i
End Sub
你把代码里的四个[0-90-9]中后面的0和9改成全角
s = "6加3等于多少,6减3等于多少,5乘3等于多少,9除3等于多少"
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.IgnoreCase = True
re.Global = True
re.Pattern = "-?([0-90-9]+(?:\.[0-90-9]+)?)([加减乘除])(-?[0-90-9]+(?:\.[0-90-9]+)?)等于(.*?),?"
Dim arr(1) As Double
For Each i In re.Execute(s)
For j = 0 To 2 Step 2
s = i.SubMatches(j)
For k = 1 To Len(s)
If Asc(Mid(s, k, 1)) < 0 Then Mid(s, k, 1) = Chr(Asc(Mid(s, k, 1)) + 23680)
Next k
arr(j \ 2) = Val(s)
Next j
Select Case i.SubMatches(1)
Case "加"
s1 = arr(0) & "+" & arr(1) & "=" & (arr(0) + arr(1))
Case "减"
s1 = arr(0) & "-" & arr(1) & "=" & (arr(0) - arr(1))
Case "乘"
s1 = arr(0) & "*" & arr(1) & "=" & (arr(0) * arr(1))
Case "除"
s1 = arr(0) & "/" & arr(1) & "=" & (arr(0) / arr(1))
End Select
MsgBox s1
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询