简单的求VB最大最小值
欲求4个通过计算得到的数(这4个数已经有了)中的最大值、最小值,怎么编程?另外,对4个文本框里数进行排序,然后在其后面的文本框中显示排序顺序,怎么弄?谢谢!弄好了再加分!...
欲求4个通过计算得到的数(这4个数已经有了)中的最大值、最小值,怎么编程?
另外,对4个文本框里数进行排序,然后在其后面的文本框中显示排序顺序,怎么弄?谢谢!
弄好了再加分! 展开
另外,对4个文本框里数进行排序,然后在其后面的文本框中显示排序顺序,怎么弄?谢谢!
弄好了再加分! 展开
2009-04-29
展开全部
Private Sub Command1_Click()
Dim a(3) As Integer
For i = LBound(a) To UBound(a)
a(i) = InputBox("输入数值")
Print "a("; i; ")="; a(i)
Next i
m = a(0)
For i = LBound(a) + 1 To UBound(a)
If a(i) > m Then
m = a(i)
End If
Next i
Print "the max is "; m
End Sub
这是计算最大值的,如果要计算最小值,就把if语句中的a(i) > m 改成 a(i) < m即可
Dim a(3) As Integer
For i = LBound(a) To UBound(a)
a(i) = InputBox("输入数值")
Print "a("; i; ")="; a(i)
Next i
m = a(0)
For i = LBound(a) + 1 To UBound(a)
If a(i) > m Then
m = a(i)
End If
Next i
Print "the max is "; m
End Sub
这是计算最大值的,如果要计算最小值,就把if语句中的a(i) > m 改成 a(i) < m即可
展开全部
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
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.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Label1.Caption = "最大数"
Label2.Caption = "最小数"
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.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Label1.Caption = "最大数"
Label2.Caption = "最小数"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |