十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
vb2010写的:
我们提供的服务有:成都网站设计、网站制作、微信公众号开发、网站优化、网站认证、广元ssl等。为上千企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的广元网站制作公司
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim str As String = ""
Dim a(30) As Integer
Dim temp As Integer
str = str "生成的30个随机数字是 " vbCrLf
For i = 1 To 30
a(i) = Int(Rnd() * 50 + 1)
str = str a(i) " "
If i Mod 10 = 0 Then
str = str vbCrLf
End If
Next
str = str vbCrLf
For i = 1 To 30
For j = 1 To 30 - i
If a(j) a(j + 1) Then
temp = a(j + 1)
饥明 a(j + 1) = a(j)
a(j) = temp
End If
Next j
Next i
str = str 粗肢孝"排序后的数字是 " vbCrLf
For i = 1 To 30
str = str a(i) " "
If i Mod 10 = 0 Then
岩稿 str = str vbCrLf
End If
Next
TextBox6.Text = str
End Sub
运行结果:
生成的30个随机数字是
36 27 29 15 16 39 1 39 41 36
3 21 44 40 19 49 44 3 48 19
27 39 3 30 24 15 32 33 14 14
排序后的数字是
49 48 44 44 41 40 39 39 39 36
36 33 32 30 29 27 27 24 21 19
19 16 15 15 14 14 3 3 3 1
用不到2个命令按钮 1个就够
在按钮的过程中写如下代码
dim x as long , y as long ,z as long ,j as long ,n as long
dim k as integer
x = val(text1.text)
y = val(text2.text)
z = val(text3.text)
j = val(text4.text)
if x = then k = k+1
if y= then k = k+1
if z= then k = k+1
if j= then k = k+1
' 若输入的数有负数举清 则必须先在这里写正模前下 n=-.....()
do
if x 0 and n = x then
text5.text = text5.text " " x
k = k +1
end if
if y 0 and n = then
text5.text = text5.text " " y
k = k +1
end if
if z 0 and n = z then
text5.text = text5.text " " z
k = k +1
end if
if j 0 and n = j then
text5.text = text.text "码汪 " j
k = k +1
end if
if k = 4 then exit for
n=n+1
loop
这是VB的代码。。。。 不知道点虐 适用不
'vb点虐 2008
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a(9), b(9) As Integer
Randomize()
For i = 0 To 9
a(i) = Int(Rnd() * (101))
Next
System.Array.Copy(a, b, 10) '衡仔复制数组
System.Array.Sort(b) '排序,数组b就是虚枝小咐誉汪到大的排列
End Sub
End Class
举个例子:比较a,b,c,d四个数字的大小,取Xmin=最小的数字。神基段例如:1,2,3,4,则Xmin=1;如果1,2,0,3,则Xmin=1,全为0时,Xmin=0
新建一个工程
上面建成一个text1再复制三个,生成了个控件数据
再搞一按钮,复制下面的代码就可以了,游誉测试没有问题,
Dim a(4) ‘定义数组
Private Sub Command1_Click()
For j = 1 To 4
a(j) = Text1(j - 1).Text ’这里为了简单我就用数组控件了
Min = a(1)
flag = 1
For i = 2 To 4
a(i) = Text1(i - 1).Text
If Min a(i) Then
If Min = 0 Then
Min = a(i)
End If
If a(i) = 0 Then
Min = Min
End If
Min = a(i)
flag = i
End If
Next i
Next j
MsgBox Min
End Sub
测试没有问题哦……
如果不想用控件数组的请,建四个文本框,写上a(1) = Text1.Text
a(2)=text2.text…锋或………