samysam 2021-03-01 23:18 采纳率: 100%
浏览 184
已采纳

请教用vb.net编写抽签程序的问题

大家好!我大学专业不是计算机,读了个文科。工作后发发觉计算机编程很有趣,也想编些适合自己工作的软件。目前在自学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

  • 写回答

5条回答 默认 最新

  • soar3033 2021-03-02 19:57
    关注
                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

    把ReDim allNames(j - 1)   ReDim allNames(j + 1) 都注释掉看看

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改