I was making a seat randomizer for my English teacher and I wanted to make it so that it re-randomizes when 2 people who are flagged for talking sit in the same group, it re-randomizes. But it doesnt the Arrays of HashSet I vant to create.
Code:
Imports System.IO
Imports System.IO.Path
Public Class Form1
Dim RandomClass As New Random()
Dim RememberSet As New HashSet(Of Integer)
Dim RandomNumber As Integer
Dim tbResults As Object
Dim File As String
Dim Group() As HashSet(Of String)
Dim Bans() As HashSet(Of String)
Public Function OpenFile() As String
'declare a string, this is will contain the filename that we return
Dim strFileName = ""
'declare a new open file dialog
Dim fileDialogBox As New OpenFileDialog()
'add file filters, this step is optional, but if you notice the screenshot
'above it does not look clean if you leave it off, I explained in further
'detail on my site how to add/modify these values
fileDialogBox.Filter = "CSV Files (*.csv)|*.csv|All files (*.*)|*.*"
'this sets the default filter that we created in the line above, if you don't
'set a FilterIndex it will automatically default to 1
fileDialogBox.FilterIndex = 1
'this line tells the file dialog box what folder it should start off in first
'I selected the users my document folder
fileDialogBox.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
'Check to see if the user clicked the open button
If (fileDialogBox.ShowDialog() = DialogResult.OK) Then
strFileName = fileDialogBox.FileName
Else
MsgBox("You did not select a file!")
End If
'return the name of the file
Return strFileName
End Function
Private Function Randomiser()
Dim ret As Boolean
RememberSet.Clear()
On Error GoTo skip
While RememberSet.Count < ComboBox1.Items.Count
RandomNumber = RandomClass.Next(0, ComboBox1.Items.Count)
If RememberSet.Add(RandomNumber) Then
Group(RememberSet.Count / 4).Add(ComboBox1.Items(RandomNumber))
DirectCast(Me.Controls("label" & RememberSet.Count), Label).Text = ComboBox1.Items(RandomNumber)
End If
End While
For Each grup In Group
For Each ban In Bans
If Not ban.IsProperSubsetOf(grup) Then ret = True
Next
Next
Return ret
skip:
End Function
Private Sub RandomLoader(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim i As Integer
ComboBox1.Items.Clear()
ComboBox1.Items.AddRange(IO.File.ReadAllLines("Class - " & ComboBox2.Text & ".txt"))
For Each item In IO.File.ReadAllLines("Ban - " & ComboBox2.Text & ".txt")
Bans(i) = New HashSet(Of String)(Split(item, "."))
i = i + 1
Next
End Sub
Private Sub Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
LoadItems()
End Sub
Private Sub LoadItems()
ComboBox2.Items.Clear()
Dim strPath As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\"
Dim dirInfo As New IO.DirectoryInfo(strPath)
For Each file As FileInfo In dirInfo.GetFiles("Class - *.txt", SearchOption.TopDirectoryOnly)
Dim sSplitParts() As String
Dim sSplitParts2() As String
sSplitParts = Split(file.Name, ".")
sSplitParts2 = Split(sSplitParts(0), " - ")
ComboBox2.Items.Add(sSplitParts2(1))
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fileopen As String = OpenFile()
If Not fileopen = "" Then
Dim rawcsv() As String = IO.File.ReadAllLines(fileopen)
Dim Names() As String = Split(rawcsv(0), ";")
Dim Bans() As String = Split(rawcsv(1), ";")
System.IO.File.WriteAllLines("Class - " & System.IO.Path.GetFileNameWithoutExtension(fileopen) & ".txt", Names)
System.IO.File.WriteAllLines("Ban - " & System.IO.Path.GetFileNameWithoutExtension(fileopen) & ".txt", Bans)
LoadItems()
End If
End Sub
Private Sub BanChecker(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Do Until Randomiser()
Loop
End Sub
End Class