Private Sub cmdAns_Click()
Dim x, y As Integer
x = Val(txtNum1.Text)
y = Val(txtNum2.Text)
Ans = 1
Do Until (i > x Or i > y) '直至大於其中一個數就停
i = 2
Do Until (i > x Or i > y)
If x Mod i = 0 And y Mod i = 0 Then
x = x / i
y = y / i
Ans = Ans * i
Exit Do
End If
i = i + 1 '下一個
Loop
Loop
MsgBox "最大公因數是" & Ans
MsgBox "最小公倍數是" & Ans * x * y