关于VB 求五位数的各个数字之和的问题

来源:百度知道 编辑:UC知道 时间:2024/05/18 09:04:53
要求创建一个VB程序:对输入的五位正整数分离出它的个位,十位,百位,千位,万位,并求各个数字的和

我的代码:
Private Sub Command1_Click()
Dim n As Integer, m As Integer, x As Integer, y As Integer, z As Integer, w As Integer
n = InputBox("请输入一个五位数:", "数据输入", 12345)
m = Left(n, 1)
x = Mid(n, 2, 1)
y = Mid(n, 3, 1)
z = Mid(n, 4, 1)
w = Right(n, 1)
Text1.Text = m + x + y + z + w

End Sub

Private Sub Command2_Click()
End
End Sub

可是输入“66666”或者“55555”等数字就算不出来了。麻烦高手指点一下了。谢谢:)

这样就行了

Private Sub Command1_Click()
Dim n As String, m As Integer, x As Integer, y As Integer, z As Integer, w As Integer
n = InputBox("请输入一个五位数:", "数据输入", 12345)
m = Left(n, 1)
x = Mid(n, 2, 1)
y = Mid(n, 3, 1)
z = Mid(n, 4, 1)
w = Right(n, 1)
Text1.Text = m + x + y + z + w
End Sub