一题多解的奇怪算法,不太明白

xuzhe1111 2003-02-11 10:45:06
现有四个文本框,一个按钮,在其中三个输入数字后,按按钮,会在第四个文本框中显示最大的数字,有两种方法:
1.
private sub cmdmax_click
dim int1 as integer,int2 as integer,int3 as integer
int1=cint(text1.text):int2=cint(text2.text):int3=cint(text3.text)
if int1>int2 then
if int1>int3 then
textmax.text=int1
else
textmax.text=int3
end if
else
if int3>int2 then
textmax.text=int3
else
textmax.text=int2
end if
end if
end sub
这一种我明白,可是第二种就不明白了,请各位为我讲讲,谢谢
2.
private sub cmdmax_click
dim int1 as integer,int2 as integer,int3 as integer,intmax as _ integer
int1=cint(text1.text):int2=cint(text2.text):int3=cint(text3.text)
intmax=int1
if intmax<int2 then
intmax=int2
end if
if intmax<int3 then
intmax=int3
end if
textmax.text=intmax
end sub
如果这样的话,如果intmax同时小于int2和int3,那么textmax.text该显示什么?int2 or int3?
...全文
75 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
佛的光辉 2003-02-11
  • 打赏
  • 举报
回复
如果intmax同时小于int2和int3,那么
if intmax<int2 then
intmax=int2
end if
以后intmax就和int2相等
if intmax<int3 then
intmax=int3
end if
就是比较int2和int3得大小
northwolves 2003-02-11
  • 打赏
  • 举报
回复
int3.

可以这样:
Function max(ByVal int1 As Integer, ByVal int2 As Integer, ByVal int3 As Integer) As Integer
max = IIf(int1 >= int2, int1, int2)
max = IIf(max >= int3, max, int3)
End Function

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧