VB从数组中选出一个数

来源:百度知道 编辑:UC知道 时间:2024/05/27 14:06:25
定义一个数组,里面的数是1到30,在来一个按钮,点一个就选出一个数,选出的同时,在数组中删掉这个选出的数,请教大侠帮我写代码
说漏了一点,选出来的数是这30个中的随机一个

Dim a() As Variant

Private Sub Command1_Click()
Randomize
Dim x As Integer
If UBound(a) = 0 Then Exit Sub
x = Int(Rnd * UBound(a) + 1)
MsgBox a(x)
a(x) = ""
For i = x To UBound(a) - 1
a(i) = a(i + 1)
Next
ReDim Preserve a(i - 1)
Print
For i = 1 To UBound(a)
Print a(i);
Next
End Sub

Private Sub Form_Load()
Me.Show
For i = 1 To 30
ReDim Preserve a(i)
a(i) = i
Print a(i);
If i Mod 10 = 0 Then Print
Next
End Sub

Option Base 1
Dim n As Integer
Dim a()
Private Sub form_load()
n = 30
End Sub
Private Sub cmd1_click()
ReDim a(n)
For i = 1 To n
a(i) = i
Next i
MsgBox Str(a(n)) & "已删除"
n = n - 1
If n = 0 Then MsgBox "数据已全部删除“"
End Sub

dim a(30)
for i=1 to 30
a(i)=i
next i
private sub command1_click()
static c