实现上述功能的VB程序如下,但横线处代码有错,请改正。
Private Sub Command1_Click()
Dim a As String
Dim x As Integer, s As Integer, k As Integer
a = Text1.Text
x = 1: s = 0: k = 0
For i = 1 To Len(a)
'如果输入的不是0到9的数字或者空格,则给出错误提示后结束子程序
If (Asc(Mid(a, i, 1)) < 48 Or Asc(Mid(a, i,1)) > 57) or(Asc(Mid(a,i,1))= 32) then’Label1.Caption = "只能输入数字或空格"
Exit Sub
End If
If Mid(a, i, 1) = " " Then
s = s + Mid(a,x,i)’
x = i + 1
k = k + 1
End If
Next i
Label1.Caption = "这" + Str(k) + "个数的和为:" + Str(s)
End Sub