简单的求VB最大最小值
来源:百度知道 编辑:UC知道 时间:2024/09/12 22:30:52
另外,对4个文本框里数进行排序,然后在其后面的文本框中显示排序顺序,怎么弄?谢谢!
弄好了再加分!
private sub form_click()
dim a(4) as single,i as integer,j as integer
for i=1 to 3
for j=i+1 to 4
If a(i) > a(j) Then
a(0) = a(j)
a(j) = a(i)
a(i) = a(0)
next
next
print "从大到小的顺序是:"
print a(1),a(2),a(3),a(4)
end sub
因为我也是新手,所以我用最苯的方法
首先在窗体上准备6个文本框,一个命令按纽,3个标签。其中4个文本text1到text4用来输入数据,另外2个文本text5和text6用来显示最大和最小值,2个标签分别对应这2个文本
代码如下
Private Sub Command1_Click()
Dim a(3) As Double, max As Double, min As Double
a(0) = Text1.Text: a(1) = Text2.Text: a(2) = Text3.Text: a(3) = Text4.Text
If a(0) < a(1) Then max = a(1): min = a(0) Else max = a(0): min = a(1)
If max < a(2) Then max = a(2)
If max < a(3) Then max = a(3)
If min > a(2) Then min = a(2)
If min > a(3) Then min = a(3)
Text5.Text = max: Text6.Text = min
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Te