判断整除并求和

来源:互联网 发布:兰州知豆车体广告 编辑:程序博客网 时间:2024/05/18 14:46

判断整除并求和的步骤如下:1.打开程序。2.添加两个command和两个text。3.编写程序。

程序如下:

 Private Sub Command1_Click()
Dim m As Integer, n As Integer, d As Integer
Dim s As Long
m = Val(Text1.Text)
n = Val(Text2.Text)
d = Val(Text3.Text)
s = 0
Sum m, n, d, s
Label4.Caption = m & " 到 " & n & "之间能被" & d & "整除的数之和" & s
End Sub


Private Sub Command2_Click()
End
End Sub
Public Sub Sum(x As Integer, y As Integer, z As Integer, w As Long)
Dim i As Integer
If x > y Then
t = x: x = y: y = t
End If
For i = x To y
If i Mod z = 0 Then
w = w + i
End If
Next i


End Sub


Private Sub Text1_Keypress(keyAscii As Integer)
If Not IsNumeric(Chr(keyAscii)) And keyAscii <> 8 Then
keyAscii = 0
End If
End Sub


Private Sub Text2_KeyPress(keyAscii As Integer)
If Not IsNumeric(Chr(keyAscii)) And keyAscii <>8 Then
keyAscii = 0

End If

End sub

4.运行程序。5检查错误。6再次运行,重复操作直到成功。7保存文件。8,总结错误,记入笔记。

原创粉丝点击