ACCESS中VBA,输入两个正整数m和n,求他们两个所有的公约数
展开全部
Sub xxx()
Dim m, n, i, s
m = Val(InputBox("m="))
n = Val(InputBox("n="))
i = 1
s = m & "和" & n & "的所有公约数:"
While i <= m And i <= n
If m Mod i = 0 And n Mod i = 0 Then s = s & i & " "
i = i + 1
Wend
MsgBox s
End Sub
Sub xxx()Dim m, n, i, s
m = Val(InputBox("m="))
n = Val(InputBox("n="))
i = 1
s = m & "和" & n & "的所有公约数:"
While i <= m And i <= n
If m Mod i = 0 And n Mod i = 0 Then s = s & i & " "
i = i + 1
Wend
MsgBox s
End Sub
追问
谢谢了,能不能改成在窗口的两个文本Text5 Text7中分别输入这两个数,然后所有公约数输出在Text11中?
追答
m = Val(InputBox("m="))
n = Val(InputBox("n="))
修改为:
m = Val(Text5.Text)
n = Val(Text6.Text)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询