求一个不超过5位的十进制整数各位数值的和(例如,输入2634,输出15)
1个回答
展开全部
Text1.text 用于输入正整数
Label1.Caption 存放各位数字之和的计算结果
计算事件Command1_Click
Private Sub Command1_Click()
Dim value As Long, Result As Integer
value = Val(Text1.Text)
Do
Result = Result + value - Int(value / 10) * 10
value = Int(value / 10)
Loop Until value = 0
Label1.Caption = "各位数字之和为: " & Result
End Sub
Label1.Caption 存放各位数字之和的计算结果
计算事件Command1_Click
Private Sub Command1_Click()
Dim value As Long, Result As Integer
value = Val(Text1.Text)
Do
Result = Result + value - Int(value / 10) * 10
value = Int(value / 10)
Loop Until value = 0
Label1.Caption = "各位数字之和为: " & Result
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询