一道关于VB编程的排序题

来源:百度知道 编辑:UC知道 时间:2024/05/30 04:28:27
设计一个程序 要求如下:
分别在3个文本框随便输入数字
点击按钮后 对输入的3个数字按从小到大排序 显示在 另外3个文本框里
要求不能使用循环结构和转向语句,掌握两个数字的转换方法
我想通过iif语句完成
我的代码如下
Private Sub Command1_Click()
Dim a, b, c, d, e, f As Integer
a = CInt(Text1.Text)
b = CInt(Text2.Text)
c = CInt(Text3.Text)
Text4.Text = IIf(a > b, b, a)
Text5.Text = IIf(a > b, a, b)
d = CInt(Text4.Text)
e = CInt(Text5.Text)
Text6.Text = IIf(e > c, e, c)
Text5.Text = IIf(e > c, c, e)
Text4.Text = IIf(e > d, d, e)
Text5.Text = IIf(e > d, e, d)
End Sub

但是有问题 哪位帮忙调试一下

给你修改并优化了一下:
Private Sub Command1_Click()
Dim a, b, c, d, e As Integer
a = CInt(Text1.Text)
b = CInt(Text2.Text)
c = CInt(Text3.Text)
Text4.Text = IIf(IIf(a > b, b, a) > c, c, IIf(a > b, b, a))
Text6.Text = IIf(IIf(a > b, a, b) > c, IIf(a > b, a, b), c)
d = CInt(Text4.Text)
e = CInt(Text6.Text)
Text5.Text = IIf(IIf(a > b, b, a) = d, IIf(IIf(a > b, a, b) = e, c, IIf(a > b, a, b)), IIf(a > b, b, a))
End Sub