【加试题】小龙编写了一个简易加法器VB程序,运行界面如图所示。在文本框Text1中输入一个数字后再输入空格表示一个加数输入完毕,连续不断输入不同的加数,待所有需要相加的数输入完毕后,单击“求和”按钮Command1后,在标签label1中显示加数的个数以及总和。(数字0和空格的ASCII码分别为48、32)实现上述功能的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’{#blank#}1{#/blank#}Label1.Caption = "只能输入数字或空格"
Exit Sub
End If
If Mid(a, i, 1) = " " Then
s = s + Mid(a,x,i)’{#blank#}2{#/blank#}
x = i + 1
k = k + 1
End If
Next i
Label1.Caption = "这" + Str(k) + "个数的和为:" + Str(s)
End Sub