作业帮 > 综合 > 作业

vb关于检查算数表达式的圆括号是否配对并用COUNT统计

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/14 10:33:30
vb关于检查算数表达式的圆括号是否配对并用COUNT统计
Dim count1%
Private Sub Text1_KeyPress(KeyAscii As Integer)
if_________="(" then count1=count1+1
elseif ________=")" then _______
End If
If KeyAscii = 13 Then
if ________ then Print " 左右括号配对"
elseif _________ then print "左括号多于右括号"; count1;"个"
Else:Print "右括号多于左括号"; -count1; "个"
End If
End If
End Sub
在下划线上填入相应的内容
应该少了一个参数count2
下面是我的代码
Dim count1%
Dim count2%
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "(" Then
count1 = count1 + 1
ElseIf Chr(KeyAscii) = ")" Then
count2 = count2 + 1
End If
If KeyAscii = 13 Then
If count1 = count2 Then
Print " 左右括号配对"
ElseIf count1 > count2 Then
Print "左括号多于右括号"; count1; "个"
Else
Print "右括号多于左括号"; -count1; "个"
End If
End If
End Su