判断整除并求和

代码如下:

 

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

你可能感兴趣的:(判断整除并求和)