VB随机抽取姓名教程 要教整个过程 大神!! 100
4个回答
展开全部
稍等,正在做
数据库抽取、文本文件抽取二种抽取记录,有点击按钮抽取、定时抽取二种抽取方法。
这个“随机抽取姓名exe.rar” 是生成的exe文件,需要的话,给邮箱,发源文件。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
新建一个窗体,加入两个命令按钮,Command1的Captio改为“抽取一个”,Command1的Captio改为“加载姓名”,两个ListBox,将以下代码复制到窗体代码中,可以测试:
注,在Command2_Click事件即加载姓名中,可以修改xmCount姓名个数,并且从别的地方读取姓名。
Dim xm() As String '姓名数组
Dim xmSelected() As Boolean '姓名是否被抽取
Dim I As Long
Dim J As Long
Dim selCount As Long '已经抽取姓名的总数
Dim xmCount As Long '姓名总数
Private Sub Command1_Click()
J = 1 + Rnd * xmCount
If J = xmCount + 1 Then J = xmCount
If selCount = xmCount Then
MsgBox "所有的都抽取完了!"
Exit Sub
End If
Do Until Not xmSelected(J)
J = 1 + Rnd * xmCount
If J = xmCount + 1 Then J = xmCount
Loop
selCount = selCount + 1
xmSelected(J) = True
List2.AddItem xm(J)
End Sub
Private Sub Command2_Click()
selCount = 0
List2.Clear
List1.Clear
xmCount = 10
ReDim xm(1 To xmCount)
ReDim xmSelected(1 To xmCount)
For I = 1 To xmCount
xm(I) = "姓名" & I
xmSelected(I) = False
Next
For I = 1 To xmCount
List1.AddItem xm(I)
Next
End Sub
注,在Command2_Click事件即加载姓名中,可以修改xmCount姓名个数,并且从别的地方读取姓名。
Dim xm() As String '姓名数组
Dim xmSelected() As Boolean '姓名是否被抽取
Dim I As Long
Dim J As Long
Dim selCount As Long '已经抽取姓名的总数
Dim xmCount As Long '姓名总数
Private Sub Command1_Click()
J = 1 + Rnd * xmCount
If J = xmCount + 1 Then J = xmCount
If selCount = xmCount Then
MsgBox "所有的都抽取完了!"
Exit Sub
End If
Do Until Not xmSelected(J)
J = 1 + Rnd * xmCount
If J = xmCount + 1 Then J = xmCount
Loop
selCount = selCount + 1
xmSelected(J) = True
List2.AddItem xm(J)
End Sub
Private Sub Command2_Click()
selCount = 0
List2.Clear
List1.Clear
xmCount = 10
ReDim xm(1 To xmCount)
ReDim xmSelected(1 To xmCount)
For I = 1 To xmCount
xm(I) = "姓名" & I
xmSelected(I) = False
Next
For I = 1 To xmCount
List1.AddItem xm(I)
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先要知道有多少个名字,然后取随机数,获取对应的名字,详细的你可以加我qq问我,916112253。
追问
您可以把整个过程发一下么?谢谢
追答
Option Explicit
Private Sub Command1_Click()
Dim a(200) As String '名字数组
Dim i As Integer
'假设有200个人
For i = 0 To 200
a(i) = "第" & i & "个人"
Next
'初始化随机取数
Randomize
'随机取数
i = Int(Rnd * 201)
'显示抽到的人
Print a(i)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询