vb用子函数求两书最大公约数

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 11:15:36
vb用子函数求两书最大公约数vb用子函数求两书最大公约数vb用子函数求两书最大公约数vb用子函数求两书最大公约数一题:两个TextBox,一个Command.OptionExplicitPrivate

vb用子函数求两书最大公约数
vb用子函数求两书最大公约数

vb用子函数求两书最大公约数
vb用子函数求两书最大公约数
一题:
两个TextBox,一个Command.
Option Explicit
Private Function MaxModNum _
(ByVal a As Long, ByVal b As Long) _
As Long
Dim c As Long
c = 1
Do While c > 0
c = a Mod b
a = b
b = c
DoEvents
Loop
MaxModNum = a
End Function
Private Sub Command1_Click()
If IsNumeric(Text1.Text) = False _
Or IsNumeric(Text2.Text) = False _
Then
MsgBox "请输入有效数字."
Exit Sub
End If
MsgBox "它们的最大公约数:" & _
MaxModNum(Text1.Text, Text2.Text)
End Sub
第二题:
一个Command.
Option Explicit
Private Sub MyFunc _
(ByVal n As Integer, ByRef Sum As Long)
Dim a, ts As Long
Sum = 0
Do While n > 0
ts = 1
For a = 1 To n
ts = ts * a
DoEvents: Next
Sum = Sum + ts
n = n - 1
DoEvents
Loop
End Sub
Private Sub Command1_Click()
Dim Sum As Long
MyFunc 5, Sum
MsgBox Sum
End Sub
一帆风顺吉星到 万事如意福临门 财源广进