Answer to Question #192907 in Visual Basic for Randel

Question #192907

Hi I need assistance with a looping structure to display in a listbox 8 digit student number must be generated, first 4 digits is the present year "2021" 5th digit represents gender 2 for male and 3 for female, the last digits increments according to the number of students who have registered


1
Expert's answer
2021-05-13T05:26:13-0400
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form


    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub


    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer


    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.btnCreateStudentNumber = New System.Windows.Forms.Button()
        Me.lst8DigitStudentNumber = New System.Windows.Forms.ListBox()
        Me.rbMale = New System.Windows.Forms.RadioButton()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.rbFemale = New System.Windows.Forms.RadioButton()
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnCreateStudentNumber
        '
        Me.btnCreateStudentNumber.Location = New System.Drawing.Point(30, 126)
        Me.btnCreateStudentNumber.Name = "btnCreateStudentNumber"
        Me.btnCreateStudentNumber.Size = New System.Drawing.Size(148, 23)
        Me.btnCreateStudentNumber.TabIndex = 0
        Me.btnCreateStudentNumber.Text = "Create Student Number"
        Me.btnCreateStudentNumber.UseVisualStyleBackColor = True
        '
        'lst8DigitStudentNumber
        '
        Me.lst8DigitStudentNumber.FormattingEnabled = True
        Me.lst8DigitStudentNumber.Location = New System.Drawing.Point(211, 21)
        Me.lst8DigitStudentNumber.Name = "lst8DigitStudentNumber"
        Me.lst8DigitStudentNumber.Size = New System.Drawing.Size(135, 134)
        Me.lst8DigitStudentNumber.TabIndex = 1
        '
        'rbMale
        '
        Me.rbMale.AutoSize = True
        Me.rbMale.Checked = True
        Me.rbMale.Location = New System.Drawing.Point(19, 25)
        Me.rbMale.Name = "rbMale"
        Me.rbMale.Size = New System.Drawing.Size(48, 17)
        Me.rbMale.TabIndex = 2
        Me.rbMale.TabStop = True
        Me.rbMale.Text = "Male"
        Me.rbMale.UseVisualStyleBackColor = True
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.rbFemale)
        Me.GroupBox1.Controls.Add(Me.rbMale)
        Me.GroupBox1.Location = New System.Drawing.Point(30, 21)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(148, 81)
        Me.GroupBox1.TabIndex = 3
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Select the gender "
        '
        'rbFemale
        '
        Me.rbFemale.AutoSize = True
        Me.rbFemale.Location = New System.Drawing.Point(19, 48)
        Me.rbFemale.Name = "rbFemale"
        Me.rbFemale.Size = New System.Drawing.Size(59, 17)
        Me.rbFemale.TabIndex = 2
        Me.rbFemale.Text = "Female"
        Me.rbFemale.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(373, 179)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.lst8DigitStudentNumber)
        Me.Controls.Add(Me.btnCreateStudentNumber)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "8 digit student number"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.ResumeLayout(False)


    End Sub
    Friend WithEvents btnCreateStudentNumber As System.Windows.Forms.Button
    Friend WithEvents lst8DigitStudentNumber As System.Windows.Forms.ListBox
    Friend WithEvents rbMale As System.Windows.Forms.RadioButton
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents rbFemale As System.Windows.Forms.RadioButton


End Class




Public Class Form1
    Private studentCounter As Integer = 100
    Private Sub btnCreateStudentNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateStudentNumber.Click
        'first 4 digits is the present year "2021"


        Dim number As String = "2021"
        '5th digit represents gender 2 for male and 3 for female


        If rbMale.Checked Then
            number += "2"
        End If
        If rbFemale.Checked Then
            number += "3"
        End If


        ' the last digits increments according to the number of students who have registered
        number += studentCounter.ToString()
        lst8DigitStudentNumber.Items.Clear()
        For i As Integer = 0 To number.Length - 1
            lst8DigitStudentNumber.Items.Add(number(i))
        Next
        studentCounter += 1
    End Sub
End Class









Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS