VB中可不可以这样定义求最大最小值?

来源:百度知道 编辑:UC知道 时间:2024/06/17 09:57:20
Private Sub Form_click()
Dim a%, b%, c%, max%, min%
a = InputBox("")
b = InputBox("")
c = InputBox("")
max = a: min = a
If b > max Then max = b
If c > max Then max = c
Print "a,b,c"; "三个数最大的是"; max

If b < min Then min = b
If c < min Then min = c
Print "a,b,c"; "三个数最小的是"; min
如果数据更大呢,排除程序编写的复杂情况。

If b > max Then max = b
If c > max Then max = c
Print "a,b,c"; "三个数最大的是"; max

可能不对,仅仅是和a进行比较,假如a,b,c分别是6,9,8
输出结果是8,而不是9

if b < min Then min = b
If c < min Then min = c
Print "a,b,c"; "三个数最小的是"; min

同样,假如a,b,c分别是9,7,8
输出结果是8,而不是7

应该这样:
IF a>b then
if a>c then
a是最大值
end if
elseif b>a then
if b>c then
b是最大值
end if
elseif c>a then
if c>b then
c是最大值
end if
end if

最小值和上面相同