高分急求一个简单的VB基础编程!!!

题目:利用随机函数产生60个100~200的随机整数,将其中的偶数按由小到大的顺序排列并输出,将奇数按由大到小的顺序排列并输出要求:1、将随机产生的60个整数按每行10个... 题目:利用随机函数产生60个100~200的随机整数,将其中的偶数按由小到大的顺序排列并输出,将奇数按由大到小的顺序排列并输出
要求:
1、将随机产生的60个整数按每行10个数输出到窗体或文本框中
2、将排列好顺序的偶数和奇数分别输入到两个文本框中
展开
 我来答
Yuqi_Tan

2009-05-18 · TA获得超过8.9万个赞
知道大有可为答主
回答量:9918
采纳率:93%
帮助的人:3450万
展开全部
稍等。。。

完了!

'建立两个文本框text1,text2,并设置它们的MultiLine 属性为 ture,添加一个命令按钮command1,其它不用设定,程序会自动调整位置和大小,自动设置其它属性。

Private Sub Command1_Click()
Dim Yu(60) As Integer, Ju() As Integer, Ou() As Integer
Dim I As Integer, J As Integer, Gj As Integer, Go As Integer
Form1.Cls
Text1.Visible = True
Text2.Visible = True
Print "随机产生的60个100~200的随机整数是:"
Randomize
For I = 1 To 60
Yu(I) = Int(Rnd * 101 + 100)
If Yu(I) Mod 2 = 0 Then
Go = Go + 1
Else
Gj = Gj + 1
End If
Print Yu(I);
If I Mod 10 = 0 Then Print
Next
ReDim Ju(Gj), Ou(Go)
Gj = 0
Go = 0
For I = 1 To 60
If Yu(I) Mod 2 = 0 Then
Go = Go + 1
Ou(Go) = Yu(I)
Else
Gj = Gj + 1
Ju(Gj) = Yu(I)
End If
Next
Text1.Text = "共" + Str(Go) + "个偶数,按由小到大的顺序排列结果为:" + vbCrLf + Px(Ou(), "升序")
Text2.Text = "共" + Str(Gj) + "个奇数,按由大到小的顺序排列结果为:" + vbCrLf + Px(Ju(), "降序")
End Sub

Private Sub Form_Load()
Form1.AutoRedraw = True
Form1.BorderStyle = 1
Form1.Caption = "随机整数分类排序"
Form1.Width = 10000
Form1.Height = 6000
Command1.Width = 1000
Command1.Height = 500
Command1.Top = 5000
Command1.Left = 6500
Command1.Caption = "开始"
Print
Print "利用随机函数产生60个100~200的随机整数,将随机产生的60个整数按每行10个数输出到窗体中。"
Print
Print
Print "将其中的偶数按由小到大的顺序排列并输出到一个文本框中,将奇数按由大到小的顺序排列并输出"
Print
Print "到另一个文本框中。"
Print
Print
Print "单击【开始】按钮......"
Text1.Text = "偶数按由小到大的顺序排列结果为:" + vbCrLf
Text1.Width = 4000
Text1.Height = 2400
Text1.Top = 0
Text1.Left = 5900
Text2.Text = "奇数按由大到小的顺序排列结果为:" + vbCrLf
Text2.Width = 4000
Text2.Height = 2400
Text2.Top = 2500
Text2.Left = 5900
Text1.Visible = False
Text2.Visible = False
End Sub

Private Function Px(X() As Integer, Y As String) As String
Dim Z1 As Integer, Z2 As Integer, Th As Boolean
For Z1 = LBound(X) + 1 To UBound(X) - 1
For Z2 = Z1 + 1 To UBound(X)
Th = False
If Y = "升序" Then
If X(Z1) > X(Z2) Then Th = True
ElseIf Y = "降序" Then
If X(Z1) < X(Z2) Then Th = True
End If
If Th Then
X(0) = X(Z1)
X(Z1) = X(Z2)
X(Z2) = X(0)
End If
Next
Px = Px + Str(X(Z1))
Next
Px = Px + Str(X(Z1))
End Function

已经运行过。
fgm811215
2009-05-18 · 超过46用户采纳过TA的回答
知道小有建树答主
回答量:82
采纳率:0%
帮助的人:108万
展开全部
'加个按钮,两个文本框,文本框MultiLine属性改为true
Private Sub Command1_Click()
Dim Num(60) As Integer
Dim TempNum As Integer
Dim i As Integer, j As Integer
Randomize
For i = 1 To 60
Num(i) = 100 + 100 * Rnd
Print Num(i);
If i Mod 10 = 0 Then Print

For j = 1 To i - 1
If Num(i) < Num(j) Then
TempNum = Num(i)
Num(i) = Num(j)
Num(j) = TempNum
End If
Next j
Next i

For i = 1 To 60
If Num(i) Mod 2 = 0 Then
Text1 = Text1 & Num(i) & " "
Else
Text2 = Num(i) & " " & Text2
End If
Next i
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
刀成朝1
2009-05-18 · TA获得超过1334个赞
知道大有可为答主
回答量:763
采纳率:0%
帮助的人:695万
展开全部
'60个100~200的随机整数
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, m As Integer
Dim a(), b() As Integer
Dim str1 As String
ReDim a(0), b(0) As Integer
Randomize
For i = 1 To 60
j = Int(Rnd * 101) + 100
If j Mod 2 <> 0 Then
'奇数
k = k + 1
ReDim Preserve a(k)
a(k) = j
Else
'偶数
m = m + 1
ReDim Preserve b(m)
b(m) = j
End If
str1 = str1 & j & " "
If i Mod 10 = 0 Then str1 = str1 & vbCrLf
Next i
Text1.Text = str1 '
'在设计时设置属性Text1.MultiLine = True,Text2.MultiLine = True,Text3.MultiLine = True
str1 = "奇数共有" & k & "个" & vbCrLf
For i = 1 To k - 1
For j = i + 1 To k
If a(i) < a(j) Then m = a(i): a(i) = a(j): a(j) = m
Next j
str1 = str1 & a(i) & " "
If i Mod 10 = 0 Then str1 = str1 & vbCrLf
Next i
str1 = str1 & a(i)
Text2.Text = str1 '
k = 60 - k
str1 = "偶数共有" & k & "个" & vbCrLf
For i = 1 To k - 1
For j = i + 1 To k
If b(i) < b(j) Then m = b(i): b(i) = b(j): b(j) = m
Next j
str1 = str1 & b(i) & " "
If i Mod 10 = 0 Then str1 = str1 & vbCrLf
Next i
str1 = str1 & b(i)
Text3.Text = str1 '

End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式