一个VB程序的编写,高手进来看看,追加至最高分!
vb题目:从100~200随机产生60个数,在产生的60个数中,偶数按从小到大排序,基数从打大到小排序。要求:创建3个文本框(只能是文本框,图片框等不行):第一个文本框输...
vb题目:从100~200随机产生60个数,在产生的60个数中,偶数按从小到大排序,基数从打大到小排序。
要求:创建3个文本框(只能是文本框,图片框等不行):第一个文本框输出产生的60个随机数,第二、三个分别输出排序后的奇数和偶数;四个命令按钮,依次为:产生随机数,排序,清空,结束。
本人写的程序总是有这样和那样的问题,求一方案,希望高手踊跃提供,追加分数至最高分!
请注意,题目完整描述为:从100~200随机产生60个数,在产生的60个数中,偶数从小到大排序,奇数从大到小排序。随机产生的60个数字是没有重复的,
要求:创建3个文本框(只能是文本框,图片框等不行):第一个文本框输出产生的60个随机数,这60个数字按10个数一行排列,共6行,第二、三个分别输出排序后的奇数和偶数,奇数偶数输出没有上述text1的“按10个数一行排列”的要求,只要求有空格和换行即可;四个命令按钮,依次为:产生随机数,排序,清空,结束。
请在解答时认真审题,程序尽量简洁,我是个初学者,更希望有更加健康的程序,函数不要太复杂,最好能用基本的函数并且说明函数的意思,以便于我能更加了解整个过程,请尽量添加每步的描述,谢谢
另外,答案采纳我会认真考虑的,能运算出结果不是唯一判断标准!!谁是自己写的等问题我清楚的,尤其请kciych放心!··! 展开
要求:创建3个文本框(只能是文本框,图片框等不行):第一个文本框输出产生的60个随机数,第二、三个分别输出排序后的奇数和偶数;四个命令按钮,依次为:产生随机数,排序,清空,结束。
本人写的程序总是有这样和那样的问题,求一方案,希望高手踊跃提供,追加分数至最高分!
请注意,题目完整描述为:从100~200随机产生60个数,在产生的60个数中,偶数从小到大排序,奇数从大到小排序。随机产生的60个数字是没有重复的,
要求:创建3个文本框(只能是文本框,图片框等不行):第一个文本框输出产生的60个随机数,这60个数字按10个数一行排列,共6行,第二、三个分别输出排序后的奇数和偶数,奇数偶数输出没有上述text1的“按10个数一行排列”的要求,只要求有空格和换行即可;四个命令按钮,依次为:产生随机数,排序,清空,结束。
请在解答时认真审题,程序尽量简洁,我是个初学者,更希望有更加健康的程序,函数不要太复杂,最好能用基本的函数并且说明函数的意思,以便于我能更加了解整个过程,请尽量添加每步的描述,谢谢
另外,答案采纳我会认真考虑的,能运算出结果不是唯一判断标准!!谁是自己写的等问题我清楚的,尤其请kciych放心!··! 展开
15个回答
展开全部
6-2 03:12
首先,建立3个text和4个command,名称不改了
text1:原始数字
text2:排序后奇数
text3:排序后偶数
command1:产生随机数
command2:排序
command3:清空
command4:结束
其次,在设计状态把所有text的属性multiline修改成true,方便看数字
最后贴上程序代码,你可以拷贝尝试调试一下看看,我这里成功了:)
Option Explicit
Dim X(1 To 60) As Integer, Os() As Integer, Js() As Integer
Dim I As Integer, J As Integer
Dim N As Integer, M As Integer
Dim Temp As Integer
Private Sub Command1_Click()
Text1 = ""
For I = 1 To 60 '产生100到200的随机数
X(I) = Int(Rnd * 100) + 100
Text1 = X(I) & "," & Text1
Next I
End Sub
Private Sub Command2_Click()
N = 0
M = 0
For I = 1 To 60 '根据奇偶安排随机数进入各自数组
If X(I) Mod 2 = 0 Then
N = N + 1
ReDim Preserve Os(1 To N)
Os(N) = X(I)
Else
M = M + 1
ReDim Preserve Js(1 To M)
Js(M) = X(I)
End If
Next I
For I = 1 To N - 1 '冒泡排序排偶数
For J = I + 1 To N
If Os(I) < Os(J) Then
Temp = Os(I)
Os(I) = Os(J)
Os(J) = Temp
End If
Next J
Next I
For I = 1 To M - 1 '冒泡排序排奇数
For J = I + 1 To M
If Js(I) > Js(J) Then
Temp = Js(I)
Js(I) = Js(J)
Js(J) = Temp
End If
Next J
Next I
Text2 = ""
Text3 = ""
For I = 1 To M
Text2 = Js(I) & "," & Text2
Next I
For I = 1 To N
Text3 = Os(I) & "," & Text3
Next I
End Sub
Private Sub Command3_Click()
Text1 = ""
Text2 = ""
Text3 = ""
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Load()
Randomize '随机时钟
End Sub
6-2 13:10
最后祝你顺利哈,偶睡觉鸟,有问题给偶留言啦~
无语了,居然有人这么无耻,抄我的改了我的注释而已,我可是半夜3点多写完的程序,虽然代码仅区区几行,但是请尊重别人的成果!!
tong_ai_ya如果你会请写出自己的东西,没有必要把我的说明和变量定义都抄了过去,大家都知道写程序有很多个人习惯的,一般一看就能看出来,我对你无语,太让人心寒了。。。
楼主你好,你这个问题我晚上来帮你解决,我现在去考试了。
现在问你一个问题,100~200数字中取60个数字可否有重复?我现在写的程序是有重复的,如果你的意思是没有重复数字那么我也晚上来改哦~考试去啦嘻嘻:)
不好意思哈,又是这个点,考完试出去疯了嘿嘿~
根据你的不重复要求我更改了一个算法,大体感觉上应该是优化的,懒得算啦:P
其实我以前和楼主一样,碰到程序问题就很头疼,尤其以前网上搜资料不像现在这么多这么方便。往往一个很简单很基础的问题可以让我做一个通宵,所以我觉得现在休息的时候帮助一下其他人的程序学习很有好处,尤其有这么一个好的平台:)
说实话,楼主初学vb的话,只要能够独立看懂程序就行,然后再尝试自己动手写程序,用vb的一个好处就是F5和F8,自己找碴自己解决还是很有成就感的哦~
我专业和这个完全没有关系,但是还是对编程很有兴趣,如果楼主是编程兴趣爱好者,我们可以相互交流一下,共同进步哈:D
以下是代码,控件没有改动
Option Explicit '强制变量定义,个人习惯而已
Dim X(1 To 60) As Integer, Os() As Integer, Js() As Integer '定义数组,X是随机数字存放的数组;Os是偶数存放的数组,由于随机偶数不确定,因此采用不定长数组形式
Dim Sz(1 To 100) As Integer '这个数组用来存放100~199(上下含)的所有数字,见下述
Dim I As Integer, J As Integer
Dim N As Integer, M As Integer
Dim Temp As Integer, T As Integer '两个临时变量
Dim Si As Boolean '也是一个临时变量,用布朗值描述代表真伪判断
Private Sub Command1_Click()
Text1 = ""
For I = 1 To 100
Sz(I) = I + 99
Next I
For I = 1 To 60 '产生100到200的随机数并且取出数字不重复
Do '常规思路是每生成一个数字,就让它与之前的所有数字进行比较判断是否重复
Si = False '而这里我用了另一种思路,即将所有数字进行标记,以取出的形式获得,形象地说,可以比喻成从篮子里拿苹果:)
T = Int(Rnd * 100) + 1 '我想说,编程时同一个目标是可以由不同的过程来完成的,打开思路想咯,我没仔细考虑过两种算法的优劣,懒得去算啦,偶也不是学这个的。。。只是感觉我现在用的方法速度更快~
If Sz(T) <> 0 Then
X(I) = Sz(T)
Sz(T) = 0
Si = True
End If
Loop Until (Si = True)
If ((I - 1) Mod 10 = 0) And (I <> 1) Then '以6行形式输出,每行10个数字
Text1 = Text1 & vbCrLf '这个问题很简单,就是在文本框中加上chr(10)和chr(13),vb中可以用vbCrLf表示,就是回车和换行啦
End If
If (I - 1) Mod 10 = 0 Then
Text1 = Text1 & X(I)
Else
Text1 = Text1 & " " & X(I)
End If
Next I
End Sub
Private Sub Command2_Click()
N = 0
M = 0
For I = 1 To 60 '根据奇偶安排随机数进入各自数组
If X(I) Mod 2 = 0 Then
N = N + 1
ReDim Preserve Os(1 To N)
Os(N) = X(I)
Else
M = M + 1
ReDim Preserve Js(1 To M)
Js(M) = X(I)
End If
Next I
For I = 1 To N - 1 '冒泡排序排偶数
For J = I + 1 To N
If Os(I) < Os(J) Then
Temp = Os(I)
Os(I) = Os(J)
Os(J) = Temp
End If
Next J
Next I
For I = 1 To M - 1 '冒泡排序排奇数
For J = I + 1 To M
If Js(I) > Js(J) Then
Temp = Js(I)
Js(I) = Js(J)
Js(J) = Temp
End If
Next J
Next I
Text2 = ""
Text3 = ""
For I = 1 To M
Text2 = Js(I) & " " & Text2
Next I
For I = 1 To N
Text3 = Os(I) & " " & Text3
Next I
End Sub
Private Sub Command3_Click()
Text1 = ""
Text2 = ""
Text3 = ""
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Load()
Randomize '随机时钟 如果尝试去掉这一行,你会发现每次随机都是相同的数字:P
End Sub
首先,建立3个text和4个command,名称不改了
text1:原始数字
text2:排序后奇数
text3:排序后偶数
command1:产生随机数
command2:排序
command3:清空
command4:结束
其次,在设计状态把所有text的属性multiline修改成true,方便看数字
最后贴上程序代码,你可以拷贝尝试调试一下看看,我这里成功了:)
Option Explicit
Dim X(1 To 60) As Integer, Os() As Integer, Js() As Integer
Dim I As Integer, J As Integer
Dim N As Integer, M As Integer
Dim Temp As Integer
Private Sub Command1_Click()
Text1 = ""
For I = 1 To 60 '产生100到200的随机数
X(I) = Int(Rnd * 100) + 100
Text1 = X(I) & "," & Text1
Next I
End Sub
Private Sub Command2_Click()
N = 0
M = 0
For I = 1 To 60 '根据奇偶安排随机数进入各自数组
If X(I) Mod 2 = 0 Then
N = N + 1
ReDim Preserve Os(1 To N)
Os(N) = X(I)
Else
M = M + 1
ReDim Preserve Js(1 To M)
Js(M) = X(I)
End If
Next I
For I = 1 To N - 1 '冒泡排序排偶数
For J = I + 1 To N
If Os(I) < Os(J) Then
Temp = Os(I)
Os(I) = Os(J)
Os(J) = Temp
End If
Next J
Next I
For I = 1 To M - 1 '冒泡排序排奇数
For J = I + 1 To M
If Js(I) > Js(J) Then
Temp = Js(I)
Js(I) = Js(J)
Js(J) = Temp
End If
Next J
Next I
Text2 = ""
Text3 = ""
For I = 1 To M
Text2 = Js(I) & "," & Text2
Next I
For I = 1 To N
Text3 = Os(I) & "," & Text3
Next I
End Sub
Private Sub Command3_Click()
Text1 = ""
Text2 = ""
Text3 = ""
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Load()
Randomize '随机时钟
End Sub
6-2 13:10
最后祝你顺利哈,偶睡觉鸟,有问题给偶留言啦~
无语了,居然有人这么无耻,抄我的改了我的注释而已,我可是半夜3点多写完的程序,虽然代码仅区区几行,但是请尊重别人的成果!!
tong_ai_ya如果你会请写出自己的东西,没有必要把我的说明和变量定义都抄了过去,大家都知道写程序有很多个人习惯的,一般一看就能看出来,我对你无语,太让人心寒了。。。
楼主你好,你这个问题我晚上来帮你解决,我现在去考试了。
现在问你一个问题,100~200数字中取60个数字可否有重复?我现在写的程序是有重复的,如果你的意思是没有重复数字那么我也晚上来改哦~考试去啦嘻嘻:)
不好意思哈,又是这个点,考完试出去疯了嘿嘿~
根据你的不重复要求我更改了一个算法,大体感觉上应该是优化的,懒得算啦:P
其实我以前和楼主一样,碰到程序问题就很头疼,尤其以前网上搜资料不像现在这么多这么方便。往往一个很简单很基础的问题可以让我做一个通宵,所以我觉得现在休息的时候帮助一下其他人的程序学习很有好处,尤其有这么一个好的平台:)
说实话,楼主初学vb的话,只要能够独立看懂程序就行,然后再尝试自己动手写程序,用vb的一个好处就是F5和F8,自己找碴自己解决还是很有成就感的哦~
我专业和这个完全没有关系,但是还是对编程很有兴趣,如果楼主是编程兴趣爱好者,我们可以相互交流一下,共同进步哈:D
以下是代码,控件没有改动
Option Explicit '强制变量定义,个人习惯而已
Dim X(1 To 60) As Integer, Os() As Integer, Js() As Integer '定义数组,X是随机数字存放的数组;Os是偶数存放的数组,由于随机偶数不确定,因此采用不定长数组形式
Dim Sz(1 To 100) As Integer '这个数组用来存放100~199(上下含)的所有数字,见下述
Dim I As Integer, J As Integer
Dim N As Integer, M As Integer
Dim Temp As Integer, T As Integer '两个临时变量
Dim Si As Boolean '也是一个临时变量,用布朗值描述代表真伪判断
Private Sub Command1_Click()
Text1 = ""
For I = 1 To 100
Sz(I) = I + 99
Next I
For I = 1 To 60 '产生100到200的随机数并且取出数字不重复
Do '常规思路是每生成一个数字,就让它与之前的所有数字进行比较判断是否重复
Si = False '而这里我用了另一种思路,即将所有数字进行标记,以取出的形式获得,形象地说,可以比喻成从篮子里拿苹果:)
T = Int(Rnd * 100) + 1 '我想说,编程时同一个目标是可以由不同的过程来完成的,打开思路想咯,我没仔细考虑过两种算法的优劣,懒得去算啦,偶也不是学这个的。。。只是感觉我现在用的方法速度更快~
If Sz(T) <> 0 Then
X(I) = Sz(T)
Sz(T) = 0
Si = True
End If
Loop Until (Si = True)
If ((I - 1) Mod 10 = 0) And (I <> 1) Then '以6行形式输出,每行10个数字
Text1 = Text1 & vbCrLf '这个问题很简单,就是在文本框中加上chr(10)和chr(13),vb中可以用vbCrLf表示,就是回车和换行啦
End If
If (I - 1) Mod 10 = 0 Then
Text1 = Text1 & X(I)
Else
Text1 = Text1 & " " & X(I)
End If
Next I
End Sub
Private Sub Command2_Click()
N = 0
M = 0
For I = 1 To 60 '根据奇偶安排随机数进入各自数组
If X(I) Mod 2 = 0 Then
N = N + 1
ReDim Preserve Os(1 To N)
Os(N) = X(I)
Else
M = M + 1
ReDim Preserve Js(1 To M)
Js(M) = X(I)
End If
Next I
For I = 1 To N - 1 '冒泡排序排偶数
For J = I + 1 To N
If Os(I) < Os(J) Then
Temp = Os(I)
Os(I) = Os(J)
Os(J) = Temp
End If
Next J
Next I
For I = 1 To M - 1 '冒泡排序排奇数
For J = I + 1 To M
If Js(I) > Js(J) Then
Temp = Js(I)
Js(I) = Js(J)
Js(J) = Temp
End If
Next J
Next I
Text2 = ""
Text3 = ""
For I = 1 To M
Text2 = Js(I) & " " & Text2
Next I
For I = 1 To N
Text3 = Os(I) & " " & Text3
Next I
End Sub
Private Sub Command3_Click()
Text1 = ""
Text2 = ""
Text3 = ""
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Load()
Randomize '随机时钟 如果尝试去掉这一行,你会发现每次随机都是相同的数字:P
End Sub
展开全部
看了楼上的楼上的代码真别扭 逆向思维是不错 不过你的逆向思维没有减少运算量
改了楼上的楼上的楼上的。。。。楼上的某位的代码
I = 1
Do While I < 61
Randomize
A(I) = Int(Rnd * (200 - 100) + 100)
If InStr(Text1.Text, A(I)) > 0 Then
Else
Text1.Text = Text1.Text & A(I) & " "
If I Mod 10 = 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & vbCrLf
I = I + 1
End If
Loop
只加了这段
这个至少看起来不那么费力InStr(Text1.Text, A(I)) 判断A(I)是否在Text1.Text中
呵呵重在参与
'############代码开始############
Option Explicit
Dim A(1 To 60) As Integer, B() As Integer, C() As Integer, D As Integer, E As Integer
Dim I As Integer, J As Integer
Dim NumStr As Integer
Private Sub Command1_Click()
Text1.Text = ""
I = 1
Do While I < 61
Randomize
A(I) = Int(Rnd * (200 - 100) + 100)
If InStr(Text1.Text, A(I)) > 0 Then
Else
Text1.Text = Text1.Text & A(I) & " "
If I Mod 10 = 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & vbCrLf
I = I + 1
End If
Loop
End Sub
Private Sub Command2_Click()
D = 0: E = 0
For I = 1 To 60
If A(I) Mod 2 = 0 Then
D = D + 1
ReDim Preserve B(1 To D)
B(D) = A(I)
Else
E = E + 1
ReDim Preserve C(1 To E)
C(E) = A(I)
End If
Next I
For I = 1 To D - 1
For J = I + 1 To D
If B(I) < B(J) Then
NumStr = B(I)
B(I) = B(J)
B(J) = NumStr
End If
Next J
Next I
For I = 1 To E - 1
For J = I + 1 To E
If C(I) > C(J) Then
NumStr = C(I)
C(I) = C(J)
C(J) = NumStr
End If
Next J
Next I
Text2.Text = ""
Text3.Text = ""
For I = 1 To E
Text2.Text = Text2.Text & C(I) & ","
If I Mod 10 = 0 Then Text2.Text = Left(Text2.Text, Len(Text2.Text) - 1) & vbCrLf
Next I
For I = 1 To D
Text3.Text = Text3.Text & B(I) & ","
If I Mod 10 = 0 Then Text3.Text = Left(Text3.Text, Len(Text3.Text) - 1) & vbCrLf
Next I
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub Command4_Click()
End
End Sub
'############代码结束############
改了楼上的楼上的楼上的。。。。楼上的某位的代码
I = 1
Do While I < 61
Randomize
A(I) = Int(Rnd * (200 - 100) + 100)
If InStr(Text1.Text, A(I)) > 0 Then
Else
Text1.Text = Text1.Text & A(I) & " "
If I Mod 10 = 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & vbCrLf
I = I + 1
End If
Loop
只加了这段
这个至少看起来不那么费力InStr(Text1.Text, A(I)) 判断A(I)是否在Text1.Text中
呵呵重在参与
'############代码开始############
Option Explicit
Dim A(1 To 60) As Integer, B() As Integer, C() As Integer, D As Integer, E As Integer
Dim I As Integer, J As Integer
Dim NumStr As Integer
Private Sub Command1_Click()
Text1.Text = ""
I = 1
Do While I < 61
Randomize
A(I) = Int(Rnd * (200 - 100) + 100)
If InStr(Text1.Text, A(I)) > 0 Then
Else
Text1.Text = Text1.Text & A(I) & " "
If I Mod 10 = 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & vbCrLf
I = I + 1
End If
Loop
End Sub
Private Sub Command2_Click()
D = 0: E = 0
For I = 1 To 60
If A(I) Mod 2 = 0 Then
D = D + 1
ReDim Preserve B(1 To D)
B(D) = A(I)
Else
E = E + 1
ReDim Preserve C(1 To E)
C(E) = A(I)
End If
Next I
For I = 1 To D - 1
For J = I + 1 To D
If B(I) < B(J) Then
NumStr = B(I)
B(I) = B(J)
B(J) = NumStr
End If
Next J
Next I
For I = 1 To E - 1
For J = I + 1 To E
If C(I) > C(J) Then
NumStr = C(I)
C(I) = C(J)
C(J) = NumStr
End If
Next J
Next I
Text2.Text = ""
Text3.Text = ""
For I = 1 To E
Text2.Text = Text2.Text & C(I) & ","
If I Mod 10 = 0 Then Text2.Text = Left(Text2.Text, Len(Text2.Text) - 1) & vbCrLf
Next I
For I = 1 To D
Text3.Text = Text3.Text & B(I) & ","
If I Mod 10 = 0 Then Text3.Text = Left(Text3.Text, Len(Text3.Text) - 1) & vbCrLf
Next I
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub Command4_Click()
End
End Sub
'############代码结束############
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请楼主将以下代码粘贴到记事本,为存为"form.frm".再用VB打开即可!
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5805
ClientLeft = 60
ClientTop = 450
ClientWidth = 5160
LinkTopic = "Form1"
ScaleHeight = 5805
ScaleWidth = 5160
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text3
Height = 1335
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 9
Top = 3720
Width = 4935
End
Begin VB.TextBox Text2
Height = 1335
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 8
Top = 2040
Width = 4935
End
Begin VB.CommandButton Command4
Caption = "结束"
Height = 495
Left = 3960
TabIndex = 7
Top = 5160
Width = 1095
End
Begin VB.CommandButton Command3
Caption = "清空"
Height = 495
Left = 2760
TabIndex = 6
Top = 5160
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "排序"
Height = 495
Left = 1560
TabIndex = 2
Top = 5160
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "产生随机数"
Height = 495
Left = 120
TabIndex = 1
Top = 5160
Width = 1335
End
Begin VB.TextBox Text1
Height = 1335
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Top = 360
Width = 4935
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "偶数(小到大排序):"
Height = 180
Left = 240
TabIndex = 5
Top = 3480
Width = 1530
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "奇数(大到小排序):"
Height = 180
Left = 240
TabIndex = 4
Top = 1800
Width = 1530
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "随机数:"
Height = 180
Left = 240
TabIndex = 3
Top = 120
Width = 630
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'############代码开始############
Option Explicit
Dim A(1 To 60) As Integer, B() As Integer, C() As Integer, D As Integer, E As Integer
Dim I As Integer, J As Integer
Dim NumStr As Integer
Private Sub Command1_Click()
Text1.Text = ""
For I = 1 To 60
Randomize
A(I) = Int(Rnd * (200 - 100) + 100)
Text1.Text = Text1.Text & A(I) & ","
If I Mod 10 = 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & vbCrLf
Next I
End Sub
Private Sub Command2_Click()
D = 0: E = 0
For I = 1 To 60
If A(I) Mod 2 = 0 Then
D = D + 1
ReDim Preserve B(1 To D)
B(D) = A(I)
Else
E = E + 1
ReDim Preserve C(1 To E)
C(E) = A(I)
End If
Next I
For I = 1 To D - 1
For J = I + 1 To D
If B(I) < B(J) Then
NumStr = B(I)
B(I) = B(J)
B(J) = NumStr
End If
Next J
Next I
For I = 1 To E - 1
For J = I + 1 To E
If C(I) > C(J) Then
NumStr = C(I)
C(I) = C(J)
C(J) = NumStr
End If
Next J
Next I
Text2.Text = ""
Text3.Text = ""
For I = 1 To E
Text2.Text = Text2.Text & C(I) & ","
If I Mod 10 = 0 Then Text2.Text = Left(Text2.Text, Len(Text2.Text) - 1) & vbCrLf
Next I
For I = 1 To D
Text3.Text = Text3.Text & B(I) & ","
If I Mod 10 = 0 Then Text3.Text = Left(Text3.Text, Len(Text3.Text) - 1) & vbCrLf
Next I
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub Command4_Click()
End
End Sub
'############代码结束############
"回答者:williamnapolv - 举人 五级 6-3 21:28",谢谢!受益了!
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5805
ClientLeft = 60
ClientTop = 450
ClientWidth = 5160
LinkTopic = "Form1"
ScaleHeight = 5805
ScaleWidth = 5160
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text3
Height = 1335
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 9
Top = 3720
Width = 4935
End
Begin VB.TextBox Text2
Height = 1335
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 8
Top = 2040
Width = 4935
End
Begin VB.CommandButton Command4
Caption = "结束"
Height = 495
Left = 3960
TabIndex = 7
Top = 5160
Width = 1095
End
Begin VB.CommandButton Command3
Caption = "清空"
Height = 495
Left = 2760
TabIndex = 6
Top = 5160
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "排序"
Height = 495
Left = 1560
TabIndex = 2
Top = 5160
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "产生随机数"
Height = 495
Left = 120
TabIndex = 1
Top = 5160
Width = 1335
End
Begin VB.TextBox Text1
Height = 1335
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Top = 360
Width = 4935
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "偶数(小到大排序):"
Height = 180
Left = 240
TabIndex = 5
Top = 3480
Width = 1530
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "奇数(大到小排序):"
Height = 180
Left = 240
TabIndex = 4
Top = 1800
Width = 1530
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "随机数:"
Height = 180
Left = 240
TabIndex = 3
Top = 120
Width = 630
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'############代码开始############
Option Explicit
Dim A(1 To 60) As Integer, B() As Integer, C() As Integer, D As Integer, E As Integer
Dim I As Integer, J As Integer
Dim NumStr As Integer
Private Sub Command1_Click()
Text1.Text = ""
For I = 1 To 60
Randomize
A(I) = Int(Rnd * (200 - 100) + 100)
Text1.Text = Text1.Text & A(I) & ","
If I Mod 10 = 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & vbCrLf
Next I
End Sub
Private Sub Command2_Click()
D = 0: E = 0
For I = 1 To 60
If A(I) Mod 2 = 0 Then
D = D + 1
ReDim Preserve B(1 To D)
B(D) = A(I)
Else
E = E + 1
ReDim Preserve C(1 To E)
C(E) = A(I)
End If
Next I
For I = 1 To D - 1
For J = I + 1 To D
If B(I) < B(J) Then
NumStr = B(I)
B(I) = B(J)
B(J) = NumStr
End If
Next J
Next I
For I = 1 To E - 1
For J = I + 1 To E
If C(I) > C(J) Then
NumStr = C(I)
C(I) = C(J)
C(J) = NumStr
End If
Next J
Next I
Text2.Text = ""
Text3.Text = ""
For I = 1 To E
Text2.Text = Text2.Text & C(I) & ","
If I Mod 10 = 0 Then Text2.Text = Left(Text2.Text, Len(Text2.Text) - 1) & vbCrLf
Next I
For I = 1 To D
Text3.Text = Text3.Text & B(I) & ","
If I Mod 10 = 0 Then Text3.Text = Left(Text3.Text, Len(Text3.Text) - 1) & vbCrLf
Next I
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub Command4_Click()
End
End Sub
'############代码结束############
"回答者:williamnapolv - 举人 五级 6-3 21:28",谢谢!受益了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上的所有答案都缺少一功能--生成的数都不重复
这是我写的一段程序,已经过调试确实可行
程序代码如下,
如有问题可以+我QQ:252529013
Dim a(1 To 60) As Integer '定义数组A(60)用来保存随即数
Private Sub Command1_Click()'生成随即数按钮
Dim s As Integer, i As Integer, j As Integer
Text1 = ""
text2=""
text3=""
For i = 1 To 60 '生成60个不同的随即数
Randomize '更换随即种子
re: s = Int(101 * Rnd + 100) '生成随即数
If same(s) = False Then '如果随即数跟已有数无一相同,则把该随即数赋予数组
a(i) = s
Else '如果随即数跟已有数相同,则回到RE重新生成新的随即数
GoTo re
End If
Next i
For i = 1 To 60 '把数组里的60个数输出
Text1 = Text1 + " " & a(i) '在TEXT1显示
Next i
End Sub
Private Sub Command2_Click() '排序按钮
Dim i As Integer, j As Integer, t As Integer
Text2 = ""
Text3 = ""
For i = 1 To 60 '用冒泡法对60个数进行从小到大的排序
For j = i To 60
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
For i = 1 To 60 '把数组按1-60读取
If a(i) Mod 2 = 0 Then '如果数为偶数就输出
Text2 = Text2 + " " & a(i) '在text2显示
End If
Next i
For i = 60 To 1 Step -1 '把数组反向读取,那么读取的数为又大到小排序
If a(i) Mod 2 <> 0 Then '如果数为奇数就输出
Text3 = Text3 + " " & a(i) '在text3显示
End If
Next i
End Sub
Private Sub Command3_Click() '清除按钮
Text1 = ""
Text2 = ""
Text3 = ""
End Sub
Private Sub Command4_Click() '结束按钮
End
End Sub
Function same(s As Integer) As Boolean '判断函数--用来判断是否生成了重复的数字
Dim i As Integer
For i = 1 To 60 '让s与整个数组进行比较,如果有相同的same函数返回true直,否则返回FALSE
If a(i) = s Then
same = True
Exit For '此处要退出循环,不然后面出现不同直就覆盖了
ElseIf a(i) <> s Then
same = False
End If
Next i
End Function
这是我写的一段程序,已经过调试确实可行
程序代码如下,
如有问题可以+我QQ:252529013
Dim a(1 To 60) As Integer '定义数组A(60)用来保存随即数
Private Sub Command1_Click()'生成随即数按钮
Dim s As Integer, i As Integer, j As Integer
Text1 = ""
text2=""
text3=""
For i = 1 To 60 '生成60个不同的随即数
Randomize '更换随即种子
re: s = Int(101 * Rnd + 100) '生成随即数
If same(s) = False Then '如果随即数跟已有数无一相同,则把该随即数赋予数组
a(i) = s
Else '如果随即数跟已有数相同,则回到RE重新生成新的随即数
GoTo re
End If
Next i
For i = 1 To 60 '把数组里的60个数输出
Text1 = Text1 + " " & a(i) '在TEXT1显示
Next i
End Sub
Private Sub Command2_Click() '排序按钮
Dim i As Integer, j As Integer, t As Integer
Text2 = ""
Text3 = ""
For i = 1 To 60 '用冒泡法对60个数进行从小到大的排序
For j = i To 60
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
For i = 1 To 60 '把数组按1-60读取
If a(i) Mod 2 = 0 Then '如果数为偶数就输出
Text2 = Text2 + " " & a(i) '在text2显示
End If
Next i
For i = 60 To 1 Step -1 '把数组反向读取,那么读取的数为又大到小排序
If a(i) Mod 2 <> 0 Then '如果数为奇数就输出
Text3 = Text3 + " " & a(i) '在text3显示
End If
Next i
End Sub
Private Sub Command3_Click() '清除按钮
Text1 = ""
Text2 = ""
Text3 = ""
End Sub
Private Sub Command4_Click() '结束按钮
End
End Sub
Function same(s As Integer) As Boolean '判断函数--用来判断是否生成了重复的数字
Dim i As Integer
For i = 1 To 60 '让s与整个数组进行比较,如果有相同的same函数返回true直,否则返回FALSE
If a(i) = s Then
same = True
Exit For '此处要退出循环,不然后面出现不同直就覆盖了
ElseIf a(i) <> s Then
same = False
End If
Next i
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
text1:原始数字
text2:排序后奇数
text3:排序后偶数
command1:产生随机数
command2:排序
command3:清空
command4:结束
其次,在设计状态把所有text的属性multiline修改成true,方便看数字
最后贴上程序代码,你可以拷贝尝试调试一下看看,我这里成功了:)
Option Explicit
Dim X(1 To 60) As Integer, Os() As Integer, Js() As Integer
Dim I As Integer, J As Integer
Dim N As Integer, M As Integer
Dim Temp As Integer
Private Sub Command1_Click()
Text1 = ""
For I = 1 To 60 '产生100到200的随机数
X(I) = Int(Rnd * 100) + 100
Text1 = X(I) & "," & Text1
Next I
End Sub
Private Sub Command2_Click()
N = 0
M = 0
For I = 1 To 60 '根据奇偶安排随机数进入各自数组
If X(I) Mod 2 = 0 Then
N = N + 1
ReDim Preserve Os(1 To N)
Os(N) = X(I)
Else
M = M + 1
ReDim Preserve Js(1 To M)
Js(M) = X(I)
End If
Next I
For I = 1 To N - 1 '冒泡排序排偶数
For J = I + 1 To N
If Os(I) < Os(J) Then
Temp = Os(I)
Os(I) = Os(J)
Os(J) = Temp
End If
Next J
Next I
For I = 1 To M - 1 '冒泡排序排奇数
For J = I + 1 To M
If Js(I) > Js(J) Then
Temp = Js(I)
Js(I) = Js(J)
Js(J) = Temp
End If
Next J
Next I
Text2 = ""
Text3 = ""
For I = 1 To M
Text2 = Js(I) & "," & Text2
Next I
For I = 1 To N
Text3 = Os(I) & "," & Text3
Next I
End Sub
Private Sub Command3_Click()
Text1 = ""
Text2 = ""
Text3 = ""
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Load()
Randomize '随机时钟
End Sub
text2:排序后奇数
text3:排序后偶数
command1:产生随机数
command2:排序
command3:清空
command4:结束
其次,在设计状态把所有text的属性multiline修改成true,方便看数字
最后贴上程序代码,你可以拷贝尝试调试一下看看,我这里成功了:)
Option Explicit
Dim X(1 To 60) As Integer, Os() As Integer, Js() As Integer
Dim I As Integer, J As Integer
Dim N As Integer, M As Integer
Dim Temp As Integer
Private Sub Command1_Click()
Text1 = ""
For I = 1 To 60 '产生100到200的随机数
X(I) = Int(Rnd * 100) + 100
Text1 = X(I) & "," & Text1
Next I
End Sub
Private Sub Command2_Click()
N = 0
M = 0
For I = 1 To 60 '根据奇偶安排随机数进入各自数组
If X(I) Mod 2 = 0 Then
N = N + 1
ReDim Preserve Os(1 To N)
Os(N) = X(I)
Else
M = M + 1
ReDim Preserve Js(1 To M)
Js(M) = X(I)
End If
Next I
For I = 1 To N - 1 '冒泡排序排偶数
For J = I + 1 To N
If Os(I) < Os(J) Then
Temp = Os(I)
Os(I) = Os(J)
Os(J) = Temp
End If
Next J
Next I
For I = 1 To M - 1 '冒泡排序排奇数
For J = I + 1 To M
If Js(I) > Js(J) Then
Temp = Js(I)
Js(I) = Js(J)
Js(J) = Temp
End If
Next J
Next I
Text2 = ""
Text3 = ""
For I = 1 To M
Text2 = Js(I) & "," & Text2
Next I
For I = 1 To N
Text3 = Os(I) & "," & Text3
Next I
End Sub
Private Sub Command3_Click()
Text1 = ""
Text2 = ""
Text3 = ""
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Load()
Randomize '随机时钟
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建议你买一张VB考级用的无忧软件,是北京的.那上面有很多你说的这种题目.有详细的解答,是演示的那种.
我以前用过那软件.
我以前用过那软件.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询