VB 数组随机排列
用1~35依次填充一个7×5的整数矩阵,显示该矩阵。之后对该矩阵的内容做随机排列单击“随机排列”按钮每次单击“随机排列”按钮,右侧的矩阵显示发生变化...
用1~35依次填充一个7×5的整数矩阵,显示该矩阵。之后对该矩阵的内容做随机排列单击“随机排列”按钮每次单击“随机排列”按钮,右侧的矩阵显示发生变化
展开
3个回答
展开全部
方法很多,在窗体上添加一个按钮,两个标签,见下图:
窗体的AutoRedraw 属性修改为True,两个标签的AutoSize 属性修都改为True。
启动后见下图:
单击按钮先下图:
完整代码如下:
Option Explicit
Private d(7, 5) As Integer
Private a(35) As Integer
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim n As Integer
'生成1-35随机序列存入数组A
n = 0
Randomize
Do While n < 35
j = Int(Rnd * 35 + 1)
For i = 1 To n
If j = a(i) Then Exit For
Next i
If i > n Then
n = n + 1
a(n) = j
End If
Loop
'按照数组A系列重新给数组D赋值
n = 0
For i = 1 To 7
For j = 1 To 5
n = n + 1
d(i, j) = a(n)
Next j
Next i
'在标签2里显示
Label2.Caption = "" & vbCrLf
For i = 1 To 7
For j = 1 To 5
Label2.Caption = Label2.Caption & Right(" " & CStr(d(i, j)), 4)
Next j
Label2.Caption = Label2.Caption & vbCrLf
Next i
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
Dim n As Integer
'数组D初始化
n = 0
For i = 1 To 7
For j = 1 To 5
n = n + 1
d(i, j) = n
Next j
Next i
'在标签1里显示
Label1.Caption = "" & vbCrLf
For i = 1 To 7
For j = 1 To 5
Label1.Caption = Label1.Caption & Right(" " & CStr(d(i, j)), 4)
Next j
Label1.Caption = Label1.Caption & vbCrLf
Next i
End Sub
展开全部
Private Sub Command1_Click()
Cls
Randomize
CurrentX = 200
CurrentY = 100
For i = 1 To 35
Print Format(i, "00") & Space(1);
If i Mod 5 = 0 Then
CurrentX = 200
End If
Next i
Dim a(34) As Integer
CurrentX = 2000
CurrentY = 100
a(0) = Int(Rnd * 35 + 1)
For i = 1 To 34
r = Int(Rnd * 35 + 1)
For j = 0 To i - 1
If a(j) = r Then
i = i - 1
Exit For
Else
a(i) = r
End If
Next j
Next i
For i = 0 To 34
Print Format(a(i), "00") & Space(1);
If (i + 1) Mod 5 = 0 Then
CurrentX = 2000
End If
Next i
End Sub
Private Sub Form_Resize()
CurrentX = 200
CurrentY = 100
For i = 1 To 35
Print Format(i, "00") & Space(1);
If i Mod 5 = 0 Then
CurrentX = 200
End If
Next i
End Sub
追问
可否用 Visual Studio 的回答呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很少很少小鸡小鸡惊喜惊喜就登记解答解答经济系逆袭你那技术监督局就是就是几点几金额金额金额金额经济额金额金额经济额吉就地解决都觉得就地解决打击打击打击第几集妲己就地解决小鸡小鸡敞篷车哦哦们能忘记威基基十几集接电话注塑机
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询