判断整除并求和

来源:互联网 发布:apache下载64位安装版 编辑:程序博客网 时间:2024/06/06 07:26

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 AsInteger)

If Not IsNumeric(Chr(KeyAscii)) AndKeyAscii <> 8 Then

KeyAscii = 0

End If

 

 

End Sub

Private Sub Command1_Click()

Dim m As Integer, n As Integer, d AsInteger

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

 

Private Sub Text2_KeyPress(KeyAscii AsInteger)

If Not IsNumeric(Chr(KeyAscii)) AndKeyAscii <> 8 Then

KeyAscii = 0

End If

End Sub

 

Private Sub Text3_KeyPress(KeyAscii AsInteger)

If Not IsNumeric(Chr(KeyAscii)) AndKeyAscii <> 8 Then

KeyAscii = 0

End If

End Sub

原创粉丝点击