VB判断整除并整除

来源:互联网 发布:mac写入不了移动硬盘 编辑:程序博客网 时间:2024/05/18 02:47

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

'sub过程:求mn之间能d被整除的数之和

 

Public Sub sum(x As Integer, y As Integer, z As Integer, w As Long)

  Dim i As Integer

  'x>Y,交换

  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