Option Explicit On 
Option Strict On

Public Class frmStudent
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents HScrollBar1 As System.Windows.Forms.HScrollBar
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtName As System.Windows.Forms.TextBox
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents rdoMale As System.Windows.Forms.RadioButton
    Friend WithEvents rdoFemale As System.Windows.Forms.RadioButton
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents rdoSecond As System.Windows.Forms.RadioButton
    Friend WithEvents rdoFirst As System.Windows.Forms.RadioButton
    Friend WithEvents rdoThird As System.Windows.Forms.RadioButton
    Friend WithEvents rdoFourth As System.Windows.Forms.RadioButton
    Friend WithEvents rdoFifth As System.Windows.Forms.RadioButton
    Friend WithEvents rdoSixth As System.Windows.Forms.RadioButton
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents dudMonth As System.Windows.Forms.DomainUpDown
    Friend WithEvents nudDay As System.Windows.Forms.NumericUpDown
    Friend WithEvents nudYear As System.Windows.Forms.NumericUpDown
    Friend WithEvents btnShow As System.Windows.Forms.Button
    Friend WithEvents btnNew As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
    Friend WithEvents picStudent As System.Windows.Forms.PictureBox
    Friend WithEvents btnLoad As System.Windows.Forms.Button
  Friend WithEvents dlgLoad As System.Windows.Forms.OpenFileDialog
    
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container

    '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.Label1 = New System.Windows.Forms.Label()
    Me.nudDay = New System.Windows.Forms.NumericUpDown()
    Me.btnShow = New System.Windows.Forms.Button()
    Me.rdoMale = New System.Windows.Forms.RadioButton()
    Me.GroupBox1 = New System.Windows.Forms.GroupBox()
    Me.rdoFemale = New System.Windows.Forms.RadioButton()
    Me.GroupBox2 = New System.Windows.Forms.GroupBox()
    Me.rdoSixth = New System.Windows.Forms.RadioButton()
    Me.rdoFifth = New System.Windows.Forms.RadioButton()
    Me.rdoFourth = New System.Windows.Forms.RadioButton()
    Me.rdoThird = New System.Windows.Forms.RadioButton()
    Me.rdoSecond = New System.Windows.Forms.RadioButton()
    Me.rdoFirst = New System.Windows.Forms.RadioButton()
    Me.GroupBox3 = New System.Windows.Forms.GroupBox()
    Me.nudYear = New System.Windows.Forms.NumericUpDown()
    Me.dudMonth = New System.Windows.Forms.DomainUpDown()
    Me.GroupBox4 = New System.Windows.Forms.GroupBox()
    Me.picStudent = New System.Windows.Forms.PictureBox()
    Me.btnNew = New System.Windows.Forms.Button()
    Me.dlgLoad = New System.Windows.Forms.OpenFileDialog()
    Me.txtName = New System.Windows.Forms.TextBox()
    Me.btnExit = New System.Windows.Forms.Button()
    Me.btnLoad = New System.Windows.Forms.Button()
    CType(Me.nudDay, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.GroupBox1.SuspendLayout()
    Me.GroupBox2.SuspendLayout()
    Me.GroupBox3.SuspendLayout()
    CType(Me.nudYear, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.GroupBox4.SuspendLayout()
    Me.SuspendLayout()
    '
    'Label1
    '
    Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, (System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label1.Location = New System.Drawing.Point(8, 8)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(48, 32)
    Me.Label1.TabIndex = 1
    Me.Label1.Text = "Name"
    '
    'nudDay
    '
    Me.nudDay.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.nudDay.Location = New System.Drawing.Point(8, 48)
    Me.nudDay.Maximum = New Decimal(New Integer() {31, 0, 0, 0})
    Me.nudDay.Minimum = New Decimal(New Integer() {1, 0, 0, 0})
    Me.nudDay.Name = "nudDay"
    Me.nudDay.TabIndex = 1
    Me.nudDay.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
    Me.nudDay.Value = New Decimal(New Integer() {1, 0, 0, 0})
    '
    'btnShow
    '
    Me.btnShow.Location = New System.Drawing.Point(128, 152)
    Me.btnShow.Name = "btnShow"
    Me.btnShow.Size = New System.Drawing.Size(136, 32)
    Me.btnShow.TabIndex = 4
    Me.btnShow.Text = "&Show Student Profile"
    '
    'rdoMale
    '
    Me.rdoMale.Checked = True
    Me.rdoMale.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.rdoMale.Location = New System.Drawing.Point(8, 24)
    Me.rdoMale.Name = "rdoMale"
    Me.rdoMale.Size = New System.Drawing.Size(80, 16)
    Me.rdoMale.TabIndex = 0
    Me.rdoMale.TabStop = True
    Me.rdoMale.Text = "Male"
    '
    'GroupBox1
    '
    Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.rdoFemale, Me.rdoMale})
    Me.GroupBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, (System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.GroupBox1.Location = New System.Drawing.Point(8, 40)
    Me.GroupBox1.Name = "GroupBox1"
    Me.GroupBox1.Size = New System.Drawing.Size(112, 80)
    Me.GroupBox1.TabIndex = 3
    Me.GroupBox1.TabStop = False
    Me.GroupBox1.Text = "Sex"
    '
    'rdoFemale
    '
    Me.rdoFemale.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.rdoFemale.Location = New System.Drawing.Point(8, 48)
    Me.rdoFemale.Name = "rdoFemale"
    Me.rdoFemale.Size = New System.Drawing.Size(80, 16)
    Me.rdoFemale.TabIndex = 0
    Me.rdoFemale.Text = "Female"
    '
    'GroupBox2
    '
    Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.rdoSixth, Me.rdoFifth, Me.rdoFourth, Me.rdoThird, Me.rdoSecond, Me.rdoFirst})
    Me.GroupBox2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, (System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.GroupBox2.Location = New System.Drawing.Point(8, 128)
    Me.GroupBox2.Name = "GroupBox2"
    Me.GroupBox2.Size = New System.Drawing.Size(112, 176)
    Me.GroupBox2.TabIndex = 3
    Me.GroupBox2.TabStop = False
    Me.GroupBox2.Text = "Grade Level"
    '
    'rdoSixth
    '
    Me.rdoSixth.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.rdoSixth.Location = New System.Drawing.Point(8, 144)
    Me.rdoSixth.Name = "rdoSixth"
    Me.rdoSixth.Size = New System.Drawing.Size(80, 16)
    Me.rdoSixth.TabIndex = 0
    Me.rdoSixth.Text = "Sixth"
    '
    'rdoFifth
    '
    Me.rdoFifth.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.rdoFifth.Location = New System.Drawing.Point(8, 120)
    Me.rdoFifth.Name = "rdoFifth"
    Me.rdoFifth.Size = New System.Drawing.Size(80, 16)
    Me.rdoFifth.TabIndex = 0
    Me.rdoFifth.Text = "Fifth"
    '
    'rdoFourth
    '
    Me.rdoFourth.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.rdoFourth.Location = New System.Drawing.Point(8, 96)
    Me.rdoFourth.Name = "rdoFourth"
    Me.rdoFourth.Size = New System.Drawing.Size(80, 16)
    Me.rdoFourth.TabIndex = 0
    Me.rdoFourth.Text = "Fourth"
    '
    'rdoThird
    '
    Me.rdoThird.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.rdoThird.Location = New System.Drawing.Point(8, 72)
    Me.rdoThird.Name = "rdoThird"
    Me.rdoThird.Size = New System.Drawing.Size(80, 16)
    Me.rdoThird.TabIndex = 0
    Me.rdoThird.Text = "Third"
    '
    'rdoSecond
    '
    Me.rdoSecond.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.rdoSecond.Location = New System.Drawing.Point(8, 48)
    Me.rdoSecond.Name = "rdoSecond"
    Me.rdoSecond.Size = New System.Drawing.Size(80, 16)
    Me.rdoSecond.TabIndex = 0
    Me.rdoSecond.Text = "Second"
    '
    'rdoFirst
    '
    Me.rdoFirst.Checked = True
    Me.rdoFirst.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.rdoFirst.Location = New System.Drawing.Point(8, 24)
    Me.rdoFirst.Name = "rdoFirst"
    Me.rdoFirst.Size = New System.Drawing.Size(80, 16)
    Me.rdoFirst.TabIndex = 0
    Me.rdoFirst.TabStop = True
    Me.rdoFirst.Text = "First"
    '
    'GroupBox3
    '
    Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.nudYear, Me.nudDay, Me.dudMonth})
    Me.GroupBox3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, (System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.GroupBox3.Location = New System.Drawing.Point(128, 40)
    Me.GroupBox3.Name = "GroupBox3"
    Me.GroupBox3.Size = New System.Drawing.Size(136, 104)
    Me.GroupBox3.TabIndex = 3
    Me.GroupBox3.TabStop = False
    Me.GroupBox3.Text = "Date of Birth"
    '
    'nudYear
    '
    Me.nudYear.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.nudYear.Location = New System.Drawing.Point(8, 72)
    Me.nudYear.Maximum = New Decimal(New Integer() {2100, 0, 0, 0})
    Me.nudYear.Minimum = New Decimal(New Integer() {1950, 0, 0, 0})
    Me.nudYear.Name = "nudYear"
    Me.nudYear.TabIndex = 2
    Me.nudYear.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
    Me.nudYear.Value = New Decimal(New Integer() {2000, 0, 0, 0})
    '
    'dudMonth
    '
    Me.dudMonth.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.dudMonth.Items.Add("January")
    Me.dudMonth.Items.Add("February")
    Me.dudMonth.Items.Add("March")
    Me.dudMonth.Items.Add("April")
    Me.dudMonth.Items.Add("May")
    Me.dudMonth.Items.Add("June")
    Me.dudMonth.Items.Add("July")
    Me.dudMonth.Items.Add("August")
    Me.dudMonth.Items.Add("September")
    Me.dudMonth.Items.Add("October")
    Me.dudMonth.Items.Add("November")
    Me.dudMonth.Items.Add("December")
    Me.dudMonth.Location = New System.Drawing.Point(8, 24)
    Me.dudMonth.Name = "dudMonth"
    Me.dudMonth.TabIndex = 0
    Me.dudMonth.Text = "January"
    Me.dudMonth.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
    '
    'GroupBox4
    '
    Me.GroupBox4.Controls.AddRange(New System.Windows.Forms.Control() {Me.picStudent})
    Me.GroupBox4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, (System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.GroupBox4.Location = New System.Drawing.Point(272, 40)
    Me.GroupBox4.Name = "GroupBox4"
    Me.GroupBox4.Size = New System.Drawing.Size(152, 152)
    Me.GroupBox4.TabIndex = 5
    Me.GroupBox4.TabStop = False
    Me.GroupBox4.Text = "Picture"
    '
    'picStudent
    '
    Me.picStudent.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    Me.picStudent.Location = New System.Drawing.Point(8, 16)
    Me.picStudent.Name = "picStudent"
    Me.picStudent.Size = New System.Drawing.Size(136, 128)
    Me.picStudent.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
    Me.picStudent.TabIndex = 0
    Me.picStudent.TabStop = False
    '
    'btnNew
    '
    Me.btnNew.Location = New System.Drawing.Point(128, 192)
    Me.btnNew.Name = "btnNew"
    Me.btnNew.Size = New System.Drawing.Size(136, 32)
    Me.btnNew.TabIndex = 4
    Me.btnNew.Text = "&New Student Profile"
    '
    'dlgLoad
    '
    Me.dlgLoad.Filter = "JPEG Files (*.jpg)|*.jpg"
    '
    'txtName
    '
    Me.txtName.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.txtName.Location = New System.Drawing.Point(64, 8)
    Me.txtName.Name = "txtName"
    Me.txtName.Size = New System.Drawing.Size(216, 22)
    Me.txtName.TabIndex = 2
    Me.txtName.Text = ""
    '
    'btnExit
    '
    Me.btnExit.Location = New System.Drawing.Point(152, 232)
    Me.btnExit.Name = "btnExit"
    Me.btnExit.Size = New System.Drawing.Size(88, 32)
    Me.btnExit.TabIndex = 4
    Me.btnExit.Text = "E&xit"
    '
    'btnLoad
    '
    Me.btnLoad.Location = New System.Drawing.Point(288, 200)
    Me.btnLoad.Name = "btnLoad"
    Me.btnLoad.Size = New System.Drawing.Size(120, 32)
    Me.btnLoad.TabIndex = 4
    Me.btnLoad.Text = "&Load Picture"
    '
    'frmStudent
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(436, 313)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnLoad, Me.GroupBox4, Me.btnExit, Me.btnNew, Me.btnShow, Me.GroupBox3, Me.GroupBox2, Me.GroupBox1, Me.txtName, Me.Label1})
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    Me.Name = "frmStudent"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Student Identification"
    CType(Me.nudDay, System.ComponentModel.ISupportInitialize).EndInit()
    Me.GroupBox1.ResumeLayout(False)
    Me.GroupBox2.ResumeLayout(False)
    Me.GroupBox3.ResumeLayout(False)
    CType(Me.nudYear, System.ComponentModel.ISupportInitialize).EndInit()
    Me.GroupBox4.ResumeLayout(False)
    Me.ResumeLayout(False)

  End Sub

#End Region

  Dim Days(11) As Integer
  Dim Grade As String

    
  Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Close()
  End Sub

  Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
    If dlgLoad.ShowDialog() = DialogResult.OK Then
      picStudent.Image = Image.FromFile(dlgLoad.FileName)
    End If
  End Sub

  Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
    'Blank out name and picture
    txtName.Text = ""
    picStudent.Image = Nothing
  End Sub

  Private Sub frmStudent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'set numbers of days (0 index array)
    Days(0) = 31
    Days(1) = 28
    Days(2) = 31
    Days(3) = 30
    Days(4) = 31
    Days(5) = 30
    Days(6) = 31
    Days(7) = 31
    Days(8) = 30
    Days(9) = 31
    Days(10) = 30
    Days(11) = 31
    Grade = "first"
    dudMonth.SelectedIndex = 0
  End Sub

  Private Sub rdoGrade_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoFirst.CheckedChanged, rdoSecond.CheckedChanged, rdoThird.CheckedChanged, rdoFourth.CheckedChanged, rdoFifth.CheckedChanged, rdoSixth.CheckedChanged
    Dim rdoGrade As RadioButton
    rdoGrade = CType(sender, RadioButton)
    Grade = LCase(rdoGrade.Text)
  End Sub

  Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
    Dim Is_Leap As Integer
    Dim Msg As String, Age As Integer, Pronoun As String
    Dim M As Integer, D As Integer, Y As Integer
    'Check for leap year and if February is current month
    If dudMonth.SelectedIndex = 1 And nudYear.Value Mod 4 = 0 And nudYear.Value Mod 100 <> 0 Then
      Is_Leap = 1
    Else
      Is_Leap = 0
    End If
    'Check to make sure current day doesn't exceed number of days in month
    If nudDay.Value > Days(dudMonth.SelectedIndex) + Is_Leap Then
      MessageBox.Show("Only" + Str(Days(dudMonth.SelectedIndex) + Is_Leap) + " days in " + CStr(dudMonth.SelectedItem), "Invalid Birth Date", MessageBoxButtons.OK, MessageBoxIcon.Error)
      Exit Sub
    End If
    'Get current date to compute age
    M = CInt(Val(Format(Now, "MM"))) - 1 '0 index on array
    D = CInt(Val(Format(Now, "dd")))
    Y = CInt(Val(Format(Now, "yyyy")))
    Age = CInt(Y - nudYear.Value)
    If dudMonth.SelectedIndex > M Or (dudMonth.SelectedIndex = M And nudDay.Value > D) Then
      Age = Age - 1
    End If
    'Check for valid age
    If Age < 0 Then
      MessageBox.Show("Birth date is before current date.", "Invalid Birth Date", MessageBoxButtons.OK, MessageBoxIcon.Error)
      Exit Sub
    End If
    'Check to make sure name entered
    If txtName.Text = "" Then
      MessageBox.Show("The profile requires a name.", "No Name Entered", MessageBoxButtons.OK, MessageBoxIcon.Error)
      txtName.Focus()
      Exit Sub
    End If
    'Put together student profile message
    Msg = txtName.Text + " is a student in the " + Grade + " grade." + ControlChars.Cr
    If rdoMale.Checked Then
      Pronoun = "He "
    Else
      Pronoun = "She "
    End If
    Msg += Pronoun + " is" + Str(Age) + " years old." + ControlChars.Cr
    MessageBox.Show(Msg, "Student Profile", MessageBoxButtons.OK)
  End Sub
End Class
