第2个回答 2013-10-14
Private Sub Command1_Click()
Dim a, b, c As Integer
a = val(Text1.Text)
b = val(Text2.Text)
c = val(Text3.Text)
d = val(Text4.Text)
If a > b Then
If b > c Then
d = "c,b,a"
Else
If a > c Then
d = "b,c,a"
Else
d = "b,a,c"
End If
End If
Else
If b > c Then
If a > c Then
d = "c,a,b"
Else
d = "a,c,b"
End If
Else
d = "c,b,a"
End If
Text4.Text = d
End Sub
注意,你要检查在(通用)或全局变量里有没有设置a,b,c。
第3个回答 2013-10-14
Private Sub Command1_Click()
a = Text1.Text
b = Text2.Text
c = Text3.Text
Dim a, b, c As Integer
If a > b Then t = a: a = b: b = t
If a > c Then t = a: a = c: c = t
If b > c Then t = b: b = c: c = t
Text4.Text = a & "," & b & "," & c
End Sub
从小到大排序输出
第4个回答 2013-10-14
你原来的代码存在三个方面的错误:
1、“当前范围内的声明重复”这实际上是由于“先使用变量后声明”造成的。先使用如:
a = Text1.Text ,这时候VB自动认为你定义了a为字符串变量。所以,当你进行声明
Dim a, b, c As Integer
的时候,就发生了“当前范围内的声明重复”,因为a已经隐式声明过了。b、c也一样。
解决办法就是:将声明语句放在变量使用之前。改成这样:
Dim a, b, c As Integer
a = Text1.Text
b = Text2.Text
c = Text3.Text
d = Text4.Text
2、末尾的“d = Text4.Text”,应该是你将赋值方向搞反了,本来是要输出的,却变成了“输入”。
3、其中的一些判断,发生了混乱。
根据以上问题,对你的代码修改如下:
Private Sub Command1_Click()
Dim a, b, c As Integer
a = Text1.Text
b = Text2.Text
c = Text3.Text
d = Text4.Text
If a > b Then
If b > c Then
d = "a,b,c"
Else
If a > c Then
d = "a,c,b"
Else
d = "c,a,b"
End If
End If
Else
If b > c Then
If a > c Then
d = "b,a,c"
Else
d = "b,c,a"
End If
Else
d = "c,b,a"
End If
End If
Text4.Text = d
End Sub
OK!运行成功了!本回答被提问者采纳