软件界面:
这块软件是由刘金玉编程开发,可以让老师用作课堂抽背、婚礼抽奖、抽签、游戏分组等活动场合。
这款软件分为两个模式:
模式1:
在一个连续的数值范围内抽取指定个数的数值,配置完模式1后直接点击确定,然后就可以点击抽签了。
模式2:
自定义一组数值,数值之间使用中文顿号(、)隔开即可,然后自行指定在这组数值中抽取多少个,这样可以满足数组的分组。
期间会记录抽签的次数,模式1和模式2可以结合使用,可以在模式1的基础上再使用模式2,以进一步实现需求。效果如下图:
软件设计界面:
本程序代码开源(作者:刘金玉):
Option Explicit Dim mode% Private Sub Command1_Click() mode = 0 If Command1.Caption = "确定" Then Text1.Enabled = False Text2.Enabled = False Text3.Enabled = False Command1.Caption = "重新配置" Else Text1.Enabled = True Text2.Enabled = True Text3.Enabled = True Command1.Caption = "确定" End If End Sub Private Sub Command2_Click() Dim a%, b%, n%, r%, i% Randomize If mode = 0 Then a = Val(Text1.Text) b = Val(Text2.Text) n = Val(Text3.Text) '数据存储数组 Dim zs% zs = b - a ReDim da%(zs) Dim c1% '用来计数 c1 = 0 For i = a To b da(c1) = i c1 = c1 + 1 Next i '使用索引抽取 For i = 1 To n r = Int(Rnd * (zs + 1)) Text4.Text = Text4.Text & da(r) & "、" '简单处理,把最后一个数已入已经抽取过的数的位置 da(r) = da(zs) da(zs) = -1 zs = zs - 1 Next i Text4.Text = Mid(Text4.Text, 1, Len(Text4.Text) - 1) ElseIf mode = 1 Then '标记-1法 If Trim(Text5.Text) <> "" Then Dim ta$(), j% ta = Split(Text5.Text, "、") a = 0 b = UBound(ta) r = Int(Rnd * (b - a + 1) + a) n = Val(Text6.Text) Do Until n = 0 Dim tmp% tmp = 0 For j = 0 To b If Val(ta(j)) <> -1 Then tmp = tmp + 1 End If Next j ReDim tb%(tmp - 1), tbi%(tmp - 1) Dim c% c = 0 For j = 0 To UBound(ta) If Val(tmp) > c And Val(ta(j)) <> -1 Then tb(c) = Val(ta(j)) tbi(c) = j c = c + 1 End If Next j Dim a1%, b1%, r1% a1 = 0 b1 = UBound(tb) r1 = Int(Rnd * (b1 - a1 + 1) + a1) Text4.Text = Text4.Text & tb(r1) & "、" ta(tbi(r1)) = -1 n = n - 1 Loop Text4.Text = Mid(Text4.Text, 1, Len(Text4.Text) - 1) End If End If Text4.Text = Text4.Text & vbCrLf Label4.Caption = Val(Label4.Caption) + 1 End Sub Private Sub Command3_Click() mode = 1 End Sub Private Sub Label8_Click() Shell "explorer https://www.ixigua.com/home/103975774650" End Sub