vb 用inputbox函数输入3个任意整数,安从大到小顺序输出 (块if语句)

如题所述

Private Sub Form_Click()
Dim a As Single, b As Single, c As Single, z As Single
a = InputBox("输入a的值", "")
b = InputBox("输入b的值", "")
c = InputBox("输入c的值", "")

If a < b Then z = a: b = a: b = z '先把这个较小值给z,把a的值给b,然后把较小值z传递给b,保证a最后存储大的数,b存储较小数
If a < c Then z = a: c = a: c = z '同理,先把这个较小值给z,把c的值给b,然后把较小值z传递给c,保证a最后存储大的数,z存储较小数
If b < c Then z = b: b = c: c = z '再处理b和c,保证b存较大数,c存较小数

Print a; b; c '最后a,b,c就是从大到小排列

End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-10-11
Dim n(2) As Long, k As Long, i As Integer
For i = 0 To 2
n(i) = Val(InputBox("请输入第" & i + 1 & "个数"))
Next
If n(1) > n(0) Then k = n(0): n(0) = n(1): n(1) = k
If n(2) > n(0) Then k = n(0): n(0) = n(2): n(2) = k
If n(2) > n(1) Then k = n(1): n(1) = n(2): n(2) = k
MsgBox "排序后的结果:" & n(0) & "," & n(1) & "," & n(2)
第2个回答  2012-10-11
Private Sub Command1_Click()
Dim a(3) As Integer
For i = 1 To 3
a(i) = InputBox("请输入第" & i & "个数:")
Next i
For i = 1 To 2
For j = i + 1 To 3
If a(i) < a(j) Then
r = a(i)
a(i) = a(j)
a(j) = r
End If
Next j
Next i
For i = 1 To 3
Print a(i);
Next i
End Sub

vb 用inputbox函数输入3个任意整数,安从大到小顺序输出 (块if语句)
Private Sub Form_Click()Dim a As Single, b As Single, c As Single, z As Single a = InputBox("输入a的值", "")b = InputBox("输入b的值", "")c = InputBox("输入c的值", "")If a < b Then z = a: b = a: b = z '先把这个较小值给z,把a的值给b,然后把...

VB表达式,输入x,y,z三个数,按照从大到小的次序显示
Private Sub Command1_Click()x = InputBox("输入第一个数:")y = InputBox("输入第二个数:")z = InputBox("输入第三个数:")Print " x y z"Print "排序前 ", x, y, z Print "排序后 ";If x > y And x > z Then If y > z Then Print " ", x, y, ...

用VB制作“输入三个数,从大到小排序”的代码
a=inputbox("输入数字a")b=inputbox("输入数字b")c=inputbox("输入数字c")print a,b,c if b<c then t=b b=c c=t end if if a<b then t=a a=b b=t end if if b<c then t=b b=c c=t end if print"排序后的结果为";a,b,c 貌似我的方法是笨了点 但是我试了...

用VB编写一个程序,输入三个数,按从小到大的顺序输出
a = Val(InputBox("请输入第一个数"))b = Val(InputBox("请输入第二个数"))c = Val(InputBox("请输入第三个数"))If a > b Then If a > c Then Print a; c; b Else Print c; a; b End If Else If b > c Then Print b; c; a Else Print c, b, a End If End I...

vb问题用inputbox函数输入三个数
为解决上述问题,首先需明确程序的目的,即对输入的三个数进行排序。在修正后的代码中,我们定义数组`aNum(1 To 3)`用于存储输入的三个数值,并使用`InputBox`函数接收输入。接着,通过双层循环实现数值交换,确保数组中的数值按照从大到小的顺序排列。具体实现如下:vb Dim aNum(1 To 3) As ...

VB编程题 输入xyz三个数,按从小到大的次序显示
1. 利用InputBoxb函数输入3个数,存放到数值型变量中,然后对其进行比较。2. 对三个数进行排序,只能通过两两对比,一般可用三条单分支IF语句来实现。3 .要显示多个数据,可以用“;”逐一显示,也可利用“&”字符串连接将多个变量连接显示。解题:先在窗体上画一个按钮,代码如下:Private Sub ...

用VB,任意输入三个实数a,b,c(用inputbox实现输入),求三个数中的最大数...
a = InputBox("输入第一个数")b = InputBox("输入第二个数")c = InputBox("输入第三个数")If a > b And a > c Then Print a; b; c & vbCrLf & a; "是最大值"If b > a And b > c Then Print a; b; c & vbCrLf & b; "是最大值"If c > a And c > b Then ...

...个程序, 输入a、b、c三个数,要求按由大到小的顺序显示... 有谁可以...
Private Sub Command1_Click()x = InputBox("输入第一个数")y = InputBox("输入第二个数")z = InputBox("输入第三个数")If x < y Then t = x: x = y: y = t If x < z Then t = x: x = z: z = t If y < z Then t = y: y = z: z = t Print x, y, z...

vb求教就是输入3个数字 然后按大小顺序输出
Sub temp()On Error GoTo ErrHandler:Nos = InputBox("请输入3个数字并用半角逗号“,”分开")Dim ResultArray(3)Nos = Nos & ","Start = 1 For i = 1 To 3 NextPos = InStr(Start, Nos, ",")ResultArray(i) = Mid(Nos, Start, NextPos - Start) * 1 Start = NextPos + 1 N...

用VB编写一个程序, 输入a、b、c三个数,要求按由大到小的顺序显示
Private Sub Form_Click()Dim A(1 To 3), I, J, X As Integer For I = 1 To 3 A(I) = Val(InputBox("请输入数字"))Next I For I = 1 To 2 For J = I + 1 To 3 If A(I) < A(J) Then X = A(I)A(I) = A(J)A(J) = X End If Next J Next I For I =...

相似回答