判断整除并求和

来源:互联网 发布:数控火焰切割机编程 编辑:程序博客网 时间:2024/05/17 07:53

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

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

 

End Sub

原创粉丝点击