Private Type student
name As String 10
End Type
Private Sub Command1_Click() '写入数据
Dim stu As student
Open "d:\studenttxt" For Random As #1 Len = Len(stu)
For i = 1 To 60
stuname = InputBox("请输入姓名")
Put #1, i, stu
Next i
Close #1
End Sub
Private Sub Command2_Click() '抽取
Randomize
Dim bb As student, n%
n = Int(Rnd 60) + 1
Open "d:\studenttxt" For Random As #1 Len = Len(bb)
Get #1, n, bb
Text1Text = bbname
Close #1
End Sub
Dim xm, n As Integer
Private Sub Command1_Click()
Static k
k = k + 1
If k Mod 2 = 1 Then
Timer1Interval = 20
Command1Caption = "停"
Else
Timer1Interval = 0
Command1Caption = "开始"
End If
End Sub
Private Sub Form_Load()
xm = Array("张三", "李四", "王五", "赵六", "钱七", "孙八", "周九", "吴十", "郑土")
n = UBound(xm) + 1
Text1FontSize = 16
Text1 = ""
Command1Caption = "开始"
End Sub
Private Sub Timer1_Timer()
x = Int(Rnd n)
Text1 = xm(x)
End Sub
Dim n As Integer
Dim a()
Private Sub Command1_Click()
If n = 0 Then '第点击执行
m = Val(Text1)
ReDim a(1 To m)
For i = 1 To m '数组a元素1至mm数
a(i) = i
Next
For i = 1 To m - 1 '随机打乱数组a元素
r = Int(Rnd m + 1)
tmp = a(i)
a(i) = a(r)
a(r) = tmp
Next
End If
n = n + 1 '计数点击数
If n > Val(Text1) Then '数超指定数抽奖结束
MsgBox "抽奖结束"
Exit Sub
End If
Text2 = a(n) '数组抽第n数由于数组随机排列所相于随机数并且重复
End Sub
给你个简单例子,Form上放一个Timer,一个Label,一个ListBox,两个Command,把下面代码粘贴进去,运行即可。有不懂的请追问。
Option Explicit
Dim i As Integer
Private Sub Command1_Click() Command1Enabled = False
Command2Enabled = True
Timer1Enabled = True
End Sub
Private Sub Command2_Click() Command1Enabled = True
Command2Enabled = False
Timer1Enabled = False
End Sub
Private Sub Form_Load() Timer1Enabled = False
Timer1Interval = 50 '滚动的速度,越小越快
Label1Caption = "等待开始"
Command1Caption = "开始"
Command2Caption = "停止"
Command2Enabled = False
List1AddItem ("张三")
List1AddItem ("李四")
List1AddItem ("王五")
List1AddItem ("赵六")
End Sub
Private Sub Timer1_Timer() If i < List1ListCount Then
List1Selected(i) = True
Label1Caption = List1List(i)
i = i + 1
Else
i = 0
End If
End Sub
希望对你有所帮助和启发。
以上就是关于用VB编程 随机抽取姓名全部的内容,包括:用VB编程 随机抽取姓名、用vb编写了这个随机抽取人名的程序,要求一个文本框,一个按钮、怎么用vb编个随机抽取人名的小程序,做到不重复并能直接打印显示已抽到的人名等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)