VB!4个文本框,一个命令按钮,输入4个数字,求最大值、最小值?
3个回答
展开全部
我的做法,仅供参考:
Public Class Form1
'VB!4个文本框,一个命令按钮,输入4个数字,求最大值、最小值?
Dim man As Integer
Dim min As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
man = TextBox1.Text
If man < TextBox2.Text Then man = TextBox2.Text
If man < TextBox3.Text Then man = TextBox3.Text
If man < TextBox4.Text Then man = TextBox4.Text
min = TextBox1.Text
If min > TextBox2.Text Then min = TextBox2.Text
If min > TextBox3.Text Then min = TextBox3.Text
If min > TextBox4.Text Then min = TextBox4.Text
MsgBox("最大数=" & man & " 最小数=" & min)
End Sub
End Class
...................................................................
黑龙江省巴彦县兴隆镇中心校 张志晨
..................................................................
Public Class Form1
'VB!4个文本框,一个命令按钮,输入4个数字,求最大值、最小值?
Dim man As Integer
Dim min As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
man = TextBox1.Text
If man < TextBox2.Text Then man = TextBox2.Text
If man < TextBox3.Text Then man = TextBox3.Text
If man < TextBox4.Text Then man = TextBox4.Text
min = TextBox1.Text
If min > TextBox2.Text Then min = TextBox2.Text
If min > TextBox3.Text Then min = TextBox3.Text
If min > TextBox4.Text Then min = TextBox4.Text
MsgBox("最大数=" & man & " 最小数=" & min)
End Sub
End Class
...................................................................
黑龙江省巴彦县兴隆镇中心校 张志晨
..................................................................
展开全部
Private Sub Command1_Click()
dim a,b,c,d as double
a = txt1.text
b = txt2.text
c = txt3.text
d = txt4.text
Print "处理前"; a, b, c, d
If a < b Then
t = a
a = b
b = t
End If
If a < c Then
t = a
a = c
c = t
End If
If a < d Then
t = a
a = d
d = t
End If
If b < c Then
t = b
b = c
d = t
End If
If b < d Then
t = b
b = d
d = t
End If
If c < d Then
t = c
c = d
d = t
End If
Print "Max=";a ;"min=";d
End Sub
典型的冒泡法 , 如果用数组的话,代码更简洁些,考虑初学者的实际情况,用这个了!
dim a,b,c,d as double
a = txt1.text
b = txt2.text
c = txt3.text
d = txt4.text
Print "处理前"; a, b, c, d
If a < b Then
t = a
a = b
b = t
End If
If a < c Then
t = a
a = c
c = t
End If
If a < d Then
t = a
a = d
d = t
End If
If b < c Then
t = b
b = c
d = t
End If
If b < d Then
t = b
b = d
d = t
End If
If c < d Then
t = c
c = d
d = t
End If
Print "Max=";a ;"min=";d
End Sub
典型的冒泡法 , 如果用数组的话,代码更简洁些,考虑初学者的实际情况,用这个了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim a, b, c, d, max, min As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
d = Val(Text4.Text)
max = a
min = a
If b > max Then
max = b
End If
If c > max Then
max = c
End If
If d > max Then
max = d
End If
Print "最大数=" & max
If b < min Then
min = b
End If
If c < min Then
min = c
End If
If d < min Then
min = d
End If
Print "最小数=" & min
End Sub
Dim a, b, c, d, max, min As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
d = Val(Text4.Text)
max = a
min = a
If b > max Then
max = b
End If
If c > max Then
max = c
End If
If d > max Then
max = d
End If
Print "最大数=" & max
If b < min Then
min = b
End If
If c < min Then
min = c
End If
If d < min Then
min = d
End If
Print "最小数=" & min
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询