ไปสมัคร id ใหม่แล้วอย่า log in ค้างไว้แล้วกัน
เอาว่าน่าจะเกิดจากการไปใช้เครื่องสาธารณะ
และลืม log out แล้วบังเอิญมีคนอื่นไปใช้ต่อ
แล้วก็บังเอิญเข้ามาที่ thaicreate
แล้วบังเอิญมาโพสต่อกระทู้นี้กระทู้เดียว
ยกผลประโยชน์ให้จำเลยค่ะ
Imports System.Windows.Forms
Imports System.Collections.Generic
Public Class Form1
'Private ButtonList As List(Of Button) = New List(Of Button)()
'Private Const MaxButtonNumber As Integer = 5
'Private AttachEventButton As Button = New Button()
'Private DetachEventButton As Button = New Button()
Dim DisplayBox As ListBox = New ListBox()
Dim RadioRandomIsOn As RadioButton = New RadioButton()
Dim RadioRandomIsOff As RadioButton = New RadioButton()
Dim NumericUpDownTotalStudentPerGroup As NumericUpDown = New NumericUpDown()
Dim submitButton As Button = New Button()
Private PassRunOnce As Boolean = False
Dim myStudentOnGroup As StudentAssignment = New StudentAssignment()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PassRunOnce = False
Dim allStudent As List(Of String) = New List(Of String)
For a As Integer = 1 To 100
allStudent.Add("นักเรียนคนที่ " + a.ToString())
Next
InitControl()
myStudentOnGroup.allStudent = allStudent
myStudentOnGroup.IsRandom = False
myStudentOnGroup.StudentPerGroup = 40
'myStudentOnGroup.OnAssigned()
RadioRandomIsOn.Checked = myStudentOnGroup.IsRandom
RadioRandomIsOff.Checked = Not myStudentOnGroup.IsRandom
NumericUpDownTotalStudentPerGroup.Minimum = 1
NumericUpDownTotalStudentPerGroup.Maximum = allStudent.Count
NumericUpDownTotalStudentPerGroup.Value = myStudentOnGroup.StudentPerGroup
PassRunOnce = True
End Sub
Private Sub InitControl()
Me.Width = 600
Me.Height = 400
DisplayBox.Location = New System.Drawing.Point(10, 10)
DisplayBox.Size = New System.Drawing.Size(300, 300)
DisplayBox.TabIndex = 0
Me.Controls.Add(DisplayBox)
RadioRandomIsOn.AutoSize = True
RadioRandomIsOn.Location = New System.Drawing.Point(320, 12)
RadioRandomIsOn.Size = New System.Drawing.Size(90, 17)
RadioRandomIsOn.TabIndex = 1
RadioRandomIsOn.Name = "RadioRandomIsOn"
RadioRandomIsOn.TabStop = True
RadioRandomIsOn.Text = "Random assigned"
RadioRandomIsOn.UseVisualStyleBackColor = True
RadioRandomIsOn.Checked = True
Me.Controls.Add(RadioRandomIsOn)
RadioRandomIsOff.AutoSize = True
RadioRandomIsOff.Location = New System.Drawing.Point(320, 32)
RadioRandomIsOff.Size = New System.Drawing.Size(90, 17)
RadioRandomIsOff.TabIndex = 2
RadioRandomIsOff.Name = "RadioRandomIsOff"
RadioRandomIsOff.TabStop = True
RadioRandomIsOff.Text = "No random assigned"
RadioRandomIsOff.UseVisualStyleBackColor = True
Me.Controls.Add(RadioRandomIsOff)
Dim tempLabel As Label = New Label()
tempLabel.AutoSize = True
tempLabel.Location = New System.Drawing.Point(317, 70)
tempLabel.Name = "tempLabel"
tempLabel.Size = New System.Drawing.Size(39, 13)
tempLabel.TabIndex = 1
tempLabel.Text = "total student per group"
Me.Controls.Add(tempLabel)
NumericUpDownTotalStudentPerGroup.Location = New System.Drawing.Point(320, 85)
NumericUpDownTotalStudentPerGroup.Name = "NumericUpDownTotalStudentPerGroup"
NumericUpDownTotalStudentPerGroup.Size = New System.Drawing.Size(90, 20)
NumericUpDownTotalStudentPerGroup.TabIndex = 3
Me.Controls.Add(NumericUpDownTotalStudentPerGroup)
submitButton.Location = New System.Drawing.Point(320, 120)
submitButton.Size = New System.Drawing.Size(80, 20)
submitButton.Text = "Submit"
Me.Controls.Add(submitButton)
AddHandler RadioRandomIsOff.CheckedChanged, AddressOf Me.RadioButton_CheckedChanged
AddHandler RadioRandomIsOn.CheckedChanged, AddressOf Me.RadioButton_CheckedChanged
AddHandler NumericUpDownTotalStudentPerGroup.ValueChanged, AddressOf Me.NumericUpDown_ValueChanged
AddHandler submitButton.Click, AddressOf Me.SubmitButton_Click
End Sub
Private Sub RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If PassRunOnce Then
myStudentOnGroup.IsRandom = RadioRandomIsOn.Checked
End If
End Sub
Private Sub NumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If PassRunOnce Then
myStudentOnGroup.StudentPerGroup = NumericUpDownTotalStudentPerGroup.Value
End If
End Sub
Private Sub SubmitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
myStudentOnGroup.OnAssigned()
DisplayBox.Items.Clear()
Dim total As Integer = 1
For i As Integer = 0 To myStudentOnGroup.TotalGroup - 1
Dim subStudent() As String = myStudentOnGroup.GetStudentGroup(i)
For j As Integer = 0 To subStudent.Length - 2 'Jagged array จะเติม สมาชิกมาให้อีกตัวเสมอ และมีค่าเป็น nothing ค่ะ
Dim tempStr As String
tempStr = total.ToString("000") + ")" _
+ " กลุ่มที่ " + (i + 1).ToString("00") _
+ " ลำดับที่ " + (j + 1).ToString("00") _
+ " " + subStudent(j)
DisplayBox.Items.Add(tempStr)
total += 1
Next
Next
DisplayBox.Refresh()
End Sub
End Class
Public Class StudentAssignment
Public TotalGroup As Integer = 0
Public StudentPerGroup As Integer = 40
Public OddStudentNumber As Integer = 0
Public IsRandom As Boolean = False
Public allStudent As List(Of String) = New List(Of String)
Private _Student()() As String
Public Sub New()
End Sub
Public Sub OnAssigned()
Dim totalStudent As Integer = allStudent.Count
Dim totalOddStudent As Integer = totalStudent Mod StudentPerGroup
Dim tempAllStudent As List(Of String) = New List(Of String)
'copy รายชื่อมาเพื่อจัดกลุ่ม
tempAllStudent.AddRange(allStudent)
TotalGroup = (totalStudent / StudentPerGroup)
If (totalOddStudent) Then
TotalGroup = TotalGroup + 1
End If
'Initial multidimention jaggged array
_Student = New String(TotalGroup)() {}
For i As Integer = 0 To TotalGroup - 1
Dim totalStudentInGroup As Integer = StudentPerGroup
If (totalOddStudent > 0) And (i = (TotalGroup - 1)) Then
totalStudentInGroup = totalOddStudent
End If
Dim subStudent(totalStudentInGroup) As String
Randomize()
For j As Integer = 0 To totalStudentInGroup - 1
Dim AssignedPosition As Integer
If (Not IsRandom) Then
AssignedPosition = 0
'ถ้าไม่สุ่มก้อเลือกคนแรกในรายชื่อทั้งหมด เสมอ
Else
'สุ่มลำดับมาจากรายชื่อทั้งหมด
AssignedPosition = CInt(Int(tempAllStudent.Count * Rnd()))
End If
subStudent(j) = tempAllStudent(AssignedPosition)
tempAllStudent.RemoveAt(AssignedPosition)
'ลบคนที่ถูกเลือกแล้วออกจากรายชื่อทั้งหมด
Next
_Student(i) = subStudent 'เพิ่มรายชื่อนักเรียนแต่ละกลุ่มเข้าไป
Next
End Sub
Public Function GetStudentGroup(ByVal groupNumber) As String()
If (groupNumber > TotalGroup - 1) Then
Return Nothing
Else
Return _Student(groupNumber)
End If
End Function
End Class