大家好!我大学专业不是计算机,读了个文科。工作后发发觉计算机编程很有趣,也想编些适合自己工作的软件。目前在自学vb.net,但属于很菜的那种
最近想编个抽签的程序,希望的功能是:
1. 通过combobox选择名单列表。目前列表是内嵌的,如果可以链接外部的txt文本文件,修改txt文本文件就可改变程序里参与抽签的名单,那就perfect了。
2. 按“开始”按钮,选中的名单在Textbox文本框里滚动
3. 按“暂停”按钮,抽出一个结果,并将其显示在另一个文本框里
4. 抽签不重复,抽一个少一个。
参考了网上一些前辈的代码,但始终做不出自己想要的效果,只能在这里求助各位大神了,希望能指点迷津
代码如下:
Public Class Form1
Dim i As Integer
Dim j As Integer
'Dim a() As String
Dim names(), randomnames() As String
Dim allNames() As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ComboBox1.Text = "" Then
MsgBox("Please select a class!")
Form1_Load(0, Nothing)
Else
Timer1.Enabled = True
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If ComboBox1.Text = "" Then
MsgBox("Please select a class!")
Form1_Load(0, Nothing)
Else
Dim b() As String = {}
Dim i, k As Integer
Timer1.Enabled = False
For i = 0 To UBound(allNames)
If TextBox1.Text = allNames(i) Then
Else
ReDim Preserve b(k)
b(k) = allNames(i)
k = k + 1
End If
Next
ReDim allNames(j - 1)
'ReDim allNames(j + 1)
For i = 0 To UBound(b)
allNames(i) = b(i)
Next
j -= 1
TextBox2.Text = TextBox2.Text & TextBox1.Text & vbCrLf
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Form1_Load(0, Nothing)
ComboBox1.Text = ""
TextBox1.Text = ""
TextBox2.Text = "已抽出名单:" & vbCrLf
Timer1.Enabled = False
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = False
TextBox1.Text = ""
names = My.Resources.names_1.Split(New Char() {ControlChars.Lf}, StringSplitOptions.RemoveEmptyEntries)
randomnames = My.Resources.names_2.Split(New Char() {ControlChars.Lf}, StringSplitOptions.RemoveEmptyEntries)
Timer1.Interval = 100
j = 7
TextBox2.Text = "已抽出名单:" & vbCrLf
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
End
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
TextBox1.Text = ""
If j = 0 Then Timer1.Enabled = False : Exit Sub
If ComboBox1.SelectedItem.ToString = "Class 5" Then
allNames = names
ElseIf ComboBox1.SelectedItem.ToString = "Class 7" Then
allNames = randomnames
Else
Form1_Load(0, Nothing)
End If
i = Int(j * Rnd())
If i < 0 Then
'End
Timer1.Enabled = False
MsgBox("已抽完")
Else
TextBox1.Text = allNames(i)
End If
End Sub
End Class