Solved

Problem with Test Score program!

Posted on 2003-12-01
7
349 Views
Last Modified: 2012-06-22
Requirement:
A teacher has 6 students,
Name (a string)
testScores (an array of five singles)
Average (single)
Must have : An array of six structure variables (because the teacher has 6 students)

The application allow to enter data for each student and calculate Average test Scores
(do not accept test scores less than 0 or > 100)
the user should be able to save the data to a file, read the data from the file and print a report showing each student’s test scores and average score

Mycode:
Public Class frmTestScores
    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

    '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.
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFileOpen As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFileSaveAs As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFilePrint As System.Windows.Forms.MenuItem
    Friend WithEvents mnuExit As System.Windows.Forms.MenuItem
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents TextBox9 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox10 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox11 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox12 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox13 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox16 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox17 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox18 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox19 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox20 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox23 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox24 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox25 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox26 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox27 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox30 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox31 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox32 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox33 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox34 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox37 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox38 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox39 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox40 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox41 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents mnuReportData As System.Windows.Forms.GroupBox
    Friend WithEvents mnuReport As System.Windows.Forms.MenuItem
    Friend WithEvents mnuReportDisplay As System.Windows.Forms.MenuItem
    Friend WithEvents txtTest5 As System.Windows.Forms.TextBox
    Friend WithEvents txtTest4 As System.Windows.Forms.TextBox
    Friend WithEvents txtTest3 As System.Windows.Forms.TextBox
    Friend WithEvents txtTest2 As System.Windows.Forms.TextBox
    Friend WithEvents txtTest1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents ofdOpenFile As System.Windows.Forms.OpenFileDialog
    Friend WithEvents sfdSaveFile As System.Windows.Forms.SaveFileDialog
    Friend WithEvents pdPrint As System.Windows.Forms.PrintDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.mnuReportData = New System.Windows.Forms.GroupBox
        Me.Label9 = New System.Windows.Forms.Label
        Me.Label8 = New System.Windows.Forms.Label
        Me.Label7 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.TextBox6 = New System.Windows.Forms.TextBox
        Me.TextBox5 = New System.Windows.Forms.TextBox
        Me.TextBox4 = New System.Windows.Forms.TextBox
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.TextBox41 = New System.Windows.Forms.TextBox
        Me.TextBox40 = New System.Windows.Forms.TextBox
        Me.TextBox39 = New System.Windows.Forms.TextBox
        Me.TextBox38 = New System.Windows.Forms.TextBox
        Me.TextBox37 = New System.Windows.Forms.TextBox
        Me.TextBox34 = New System.Windows.Forms.TextBox
        Me.TextBox33 = New System.Windows.Forms.TextBox
        Me.TextBox32 = New System.Windows.Forms.TextBox
        Me.TextBox31 = New System.Windows.Forms.TextBox
        Me.TextBox30 = New System.Windows.Forms.TextBox
        Me.TextBox27 = New System.Windows.Forms.TextBox
        Me.TextBox26 = New System.Windows.Forms.TextBox
        Me.TextBox25 = New System.Windows.Forms.TextBox
        Me.TextBox24 = New System.Windows.Forms.TextBox
        Me.TextBox23 = New System.Windows.Forms.TextBox
        Me.TextBox20 = New System.Windows.Forms.TextBox
        Me.TextBox19 = New System.Windows.Forms.TextBox
        Me.TextBox18 = New System.Windows.Forms.TextBox
        Me.TextBox17 = New System.Windows.Forms.TextBox
        Me.TextBox16 = New System.Windows.Forms.TextBox
        Me.TextBox13 = New System.Windows.Forms.TextBox
        Me.TextBox12 = New System.Windows.Forms.TextBox
        Me.TextBox11 = New System.Windows.Forms.TextBox
        Me.TextBox10 = New System.Windows.Forms.TextBox
        Me.TextBox9 = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtTest5 = New System.Windows.Forms.TextBox
        Me.txtTest4 = New System.Windows.Forms.TextBox
        Me.txtTest3 = New System.Windows.Forms.TextBox
        Me.txtTest2 = New System.Windows.Forms.TextBox
        Me.txtTest1 = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.mnuFileOpen = New System.Windows.Forms.MenuItem
        Me.mnuFileSaveAs = New System.Windows.Forms.MenuItem
        Me.MenuItem6 = New System.Windows.Forms.MenuItem
        Me.mnuFilePrint = New System.Windows.Forms.MenuItem
        Me.mnuExit = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.mnuReport = New System.Windows.Forms.MenuItem
        Me.mnuReportDisplay = New System.Windows.Forms.MenuItem
        Me.MenuItem3 = New System.Windows.Forms.MenuItem
        Me.Button1 = New System.Windows.Forms.Button
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.ofdOpenFile = New System.Windows.Forms.OpenFileDialog
        Me.sfdSaveFile = New System.Windows.Forms.SaveFileDialog
        Me.pdPrint = New System.Windows.Forms.PrintDialog
        Me.mnuReportData.SuspendLayout()
        Me.SuspendLayout()
        '
        'mnuReportData
        '
        Me.mnuReportData.Controls.Add(Me.Label9)
        Me.mnuReportData.Controls.Add(Me.Label8)
        Me.mnuReportData.Controls.Add(Me.Label7)
        Me.mnuReportData.Controls.Add(Me.Label6)
        Me.mnuReportData.Controls.Add(Me.Label5)
        Me.mnuReportData.Controls.Add(Me.Label4)
        Me.mnuReportData.Controls.Add(Me.TextBox6)
        Me.mnuReportData.Controls.Add(Me.TextBox5)
        Me.mnuReportData.Controls.Add(Me.TextBox4)
        Me.mnuReportData.Controls.Add(Me.TextBox3)
        Me.mnuReportData.Controls.Add(Me.TextBox2)
        Me.mnuReportData.Controls.Add(Me.TextBox41)
        Me.mnuReportData.Controls.Add(Me.TextBox40)
        Me.mnuReportData.Controls.Add(Me.TextBox39)
        Me.mnuReportData.Controls.Add(Me.TextBox38)
        Me.mnuReportData.Controls.Add(Me.TextBox37)
        Me.mnuReportData.Controls.Add(Me.TextBox34)
        Me.mnuReportData.Controls.Add(Me.TextBox33)
        Me.mnuReportData.Controls.Add(Me.TextBox32)
        Me.mnuReportData.Controls.Add(Me.TextBox31)
        Me.mnuReportData.Controls.Add(Me.TextBox30)
        Me.mnuReportData.Controls.Add(Me.TextBox27)
        Me.mnuReportData.Controls.Add(Me.TextBox26)
        Me.mnuReportData.Controls.Add(Me.TextBox25)
        Me.mnuReportData.Controls.Add(Me.TextBox24)
        Me.mnuReportData.Controls.Add(Me.TextBox23)
        Me.mnuReportData.Controls.Add(Me.TextBox20)
        Me.mnuReportData.Controls.Add(Me.TextBox19)
        Me.mnuReportData.Controls.Add(Me.TextBox18)
        Me.mnuReportData.Controls.Add(Me.TextBox17)
        Me.mnuReportData.Controls.Add(Me.TextBox16)
        Me.mnuReportData.Controls.Add(Me.TextBox13)
        Me.mnuReportData.Controls.Add(Me.TextBox12)
        Me.mnuReportData.Controls.Add(Me.TextBox11)
        Me.mnuReportData.Controls.Add(Me.TextBox10)
        Me.mnuReportData.Controls.Add(Me.TextBox9)
        Me.mnuReportData.Controls.Add(Me.Label3)
        Me.mnuReportData.Controls.Add(Me.Label2)
        Me.mnuReportData.Controls.Add(Me.txtTest5)
        Me.mnuReportData.Controls.Add(Me.txtTest4)
        Me.mnuReportData.Controls.Add(Me.txtTest3)
        Me.mnuReportData.Controls.Add(Me.txtTest2)
        Me.mnuReportData.Controls.Add(Me.txtTest1)
        Me.mnuReportData.Controls.Add(Me.Label1)
        Me.mnuReportData.Controls.Add(Me.TextBox1)
        Me.mnuReportData.Location = New System.Drawing.Point(8, 24)
        Me.mnuReportData.Name = "mnuReportData"
        Me.mnuReportData.Size = New System.Drawing.Size(448, 208)
        Me.mnuReportData.TabIndex = 0
        Me.mnuReportData.TabStop = False
        Me.mnuReportData.Text = "Student Data"
        '
        'Label9
        '
        Me.Label9.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Label9.Location = New System.Drawing.Point(384, 170)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(40, 16)
        Me.Label9.TabIndex = 49
        Me.Label9.Text = "Label9"
        '
        'Label8
        '
        Me.Label8.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Label8.Location = New System.Drawing.Point(384, 147)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(40, 16)
        Me.Label8.TabIndex = 48
        Me.Label8.Text = "Label8"
        '
        'Label7
        '
        Me.Label7.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Label7.Location = New System.Drawing.Point(384, 123)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(40, 16)
        Me.Label7.TabIndex = 47
        Me.Label7.Text = "Label7"
        '
        'Label6
        '
        Me.Label6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Label6.Location = New System.Drawing.Point(384, 99)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(40, 16)
        Me.Label6.TabIndex = 46
        Me.Label6.Text = "Label6"
        '
        'Label5
        '
        Me.Label5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Label5.Location = New System.Drawing.Point(384, 74)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(40, 16)
        Me.Label5.TabIndex = 45
        Me.Label5.Text = "Label5"
        '
        'Label4
        '
        Me.Label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Label4.Location = New System.Drawing.Point(384, 51)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(40, 16)
        Me.Label4.TabIndex = 44
        Me.Label4.Text = "Label4"
        '
        'TextBox6
        '
        Me.TextBox6.Location = New System.Drawing.Point(16, 168)
        Me.TextBox6.Name = "TextBox6"
        Me.TextBox6.Size = New System.Drawing.Size(104, 20)
        Me.TextBox6.TabIndex = 5
        Me.TextBox6.Text = "TextBox1"
        '
        'TextBox5
        '
        Me.TextBox5.Location = New System.Drawing.Point(16, 144)
        Me.TextBox5.Name = "TextBox5"
        Me.TextBox5.Size = New System.Drawing.Size(104, 20)
        Me.TextBox5.TabIndex = 4
        Me.TextBox5.Text = "TextBox1"
        '
        'TextBox4
        '
        Me.TextBox4.Location = New System.Drawing.Point(16, 120)
        Me.TextBox4.Name = "TextBox4"
        Me.TextBox4.Size = New System.Drawing.Size(104, 20)
        Me.TextBox4.TabIndex = 3
        Me.TextBox4.Text = "TextBox1"
        '
        'TextBox3
        '
        Me.TextBox3.Location = New System.Drawing.Point(16, 96)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(104, 20)
        Me.TextBox3.TabIndex = 2
        Me.TextBox3.Text = "TextBox1"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(16, 72)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(104, 20)
        Me.TextBox2.TabIndex = 1
        Me.TextBox2.Text = "TextBox1"
        '
        'TextBox41
        '
        Me.TextBox41.Location = New System.Drawing.Point(328, 168)
        Me.TextBox41.Name = "TextBox41"
        Me.TextBox41.Size = New System.Drawing.Size(40, 20)
        Me.TextBox41.TabIndex = 43
        Me.TextBox41.Text = "TextBox41"
        '
        'TextBox40
        '
        Me.TextBox40.Location = New System.Drawing.Point(280, 168)
        Me.TextBox40.Name = "TextBox40"
        Me.TextBox40.Size = New System.Drawing.Size(40, 20)
        Me.TextBox40.TabIndex = 42
        Me.TextBox40.Text = "TextBox40"
        '
        'TextBox39
        '
        Me.TextBox39.Location = New System.Drawing.Point(232, 168)
        Me.TextBox39.Name = "TextBox39"
        Me.TextBox39.Size = New System.Drawing.Size(40, 20)
        Me.TextBox39.TabIndex = 41
        Me.TextBox39.Text = "TextBox39"
        '
        'TextBox38
        '
        Me.TextBox38.Location = New System.Drawing.Point(184, 168)
        Me.TextBox38.Name = "TextBox38"
        Me.TextBox38.Size = New System.Drawing.Size(40, 20)
        Me.TextBox38.TabIndex = 40
        Me.TextBox38.Text = "TextBox38"
        '
        'TextBox37
        '
        Me.TextBox37.Location = New System.Drawing.Point(136, 168)
        Me.TextBox37.Name = "TextBox37"
        Me.TextBox37.Size = New System.Drawing.Size(40, 20)
        Me.TextBox37.TabIndex = 39
        Me.TextBox37.Text = "TextBox37"
        '
        'TextBox34
        '
        Me.TextBox34.Location = New System.Drawing.Point(328, 144)
        Me.TextBox34.Name = "TextBox34"
        Me.TextBox34.Size = New System.Drawing.Size(40, 20)
        Me.TextBox34.TabIndex = 36
        Me.TextBox34.Text = "TextBox34"
        '
        'TextBox33
        '
        Me.TextBox33.Location = New System.Drawing.Point(280, 144)
        Me.TextBox33.Name = "TextBox33"
        Me.TextBox33.Size = New System.Drawing.Size(40, 20)
        Me.TextBox33.TabIndex = 35
        Me.TextBox33.Text = "TextBox33"
        '
        'TextBox32
        '
        Me.TextBox32.Location = New System.Drawing.Point(232, 144)
        Me.TextBox32.Name = "TextBox32"
        Me.TextBox32.Size = New System.Drawing.Size(40, 20)
        Me.TextBox32.TabIndex = 34
        Me.TextBox32.Text = "TextBox32"
        '
        'TextBox31
        '
        Me.TextBox31.Location = New System.Drawing.Point(184, 144)
        Me.TextBox31.Name = "TextBox31"
        Me.TextBox31.Size = New System.Drawing.Size(40, 20)
        Me.TextBox31.TabIndex = 33
        Me.TextBox31.Text = "TextBox31"
        '
        'TextBox30
        '
        Me.TextBox30.Location = New System.Drawing.Point(136, 144)
        Me.TextBox30.Name = "TextBox30"
        Me.TextBox30.Size = New System.Drawing.Size(40, 20)
        Me.TextBox30.TabIndex = 32
        Me.TextBox30.Text = "TextBox30"
        '
        'TextBox27
        '
        Me.TextBox27.Location = New System.Drawing.Point(328, 120)
        Me.TextBox27.Name = "TextBox27"
        Me.TextBox27.Size = New System.Drawing.Size(40, 20)
        Me.TextBox27.TabIndex = 29
        Me.TextBox27.Text = "TextBox27"
        '
        'TextBox26
        '
        Me.TextBox26.Location = New System.Drawing.Point(280, 120)
        Me.TextBox26.Name = "TextBox26"
        Me.TextBox26.Size = New System.Drawing.Size(40, 20)
        Me.TextBox26.TabIndex = 28
        Me.TextBox26.Text = "TextBox26"
        '
        'TextBox25
        '
        Me.TextBox25.Location = New System.Drawing.Point(232, 120)
        Me.TextBox25.Name = "TextBox25"
        Me.TextBox25.Size = New System.Drawing.Size(40, 20)
        Me.TextBox25.TabIndex = 27
        Me.TextBox25.Text = "TextBox25"
        '
        'TextBox24
        '
        Me.TextBox24.Location = New System.Drawing.Point(184, 120)
        Me.TextBox24.Name = "TextBox24"
        Me.TextBox24.Size = New System.Drawing.Size(40, 20)
        Me.TextBox24.TabIndex = 26
        Me.TextBox24.Text = "TextBox24"
        '
        'TextBox23
        '
        Me.TextBox23.Location = New System.Drawing.Point(136, 120)
        Me.TextBox23.Name = "TextBox23"
        Me.TextBox23.Size = New System.Drawing.Size(40, 20)
        Me.TextBox23.TabIndex = 25
        Me.TextBox23.Text = "TextBox23"
        '
        'TextBox20
        '
        Me.TextBox20.Location = New System.Drawing.Point(328, 96)
        Me.TextBox20.Name = "TextBox20"
        Me.TextBox20.Size = New System.Drawing.Size(40, 20)
        Me.TextBox20.TabIndex = 22
        Me.TextBox20.Text = "TextBox20"
        '
        'TextBox19
        '
        Me.TextBox19.Location = New System.Drawing.Point(280, 96)
        Me.TextBox19.Name = "TextBox19"
        Me.TextBox19.Size = New System.Drawing.Size(40, 20)
        Me.TextBox19.TabIndex = 21
        Me.TextBox19.Text = "TextBox19"
        '
        'TextBox18
        '
        Me.TextBox18.Location = New System.Drawing.Point(232, 96)
        Me.TextBox18.Name = "TextBox18"
        Me.TextBox18.Size = New System.Drawing.Size(40, 20)
        Me.TextBox18.TabIndex = 20
        Me.TextBox18.Text = "TextBox18"
        '
        'TextBox17
        '
        Me.TextBox17.Location = New System.Drawing.Point(184, 96)
        Me.TextBox17.Name = "TextBox17"
        Me.TextBox17.Size = New System.Drawing.Size(40, 20)
        Me.TextBox17.TabIndex = 19
        Me.TextBox17.Text = "TextBox17"
        '
        'TextBox16
        '
        Me.TextBox16.Location = New System.Drawing.Point(136, 96)
        Me.TextBox16.Name = "TextBox16"
        Me.TextBox16.Size = New System.Drawing.Size(40, 20)
        Me.TextBox16.TabIndex = 18
        Me.TextBox16.Text = "TextBox16"
        '
        'TextBox13
        '
        Me.TextBox13.Location = New System.Drawing.Point(328, 72)
        Me.TextBox13.Name = "TextBox13"
        Me.TextBox13.Size = New System.Drawing.Size(40, 20)
        Me.TextBox13.TabIndex = 15
        Me.TextBox13.Text = "TextBox13"
        '
        'TextBox12
        '
        Me.TextBox12.Location = New System.Drawing.Point(280, 72)
        Me.TextBox12.Name = "TextBox12"
        Me.TextBox12.Size = New System.Drawing.Size(40, 20)
        Me.TextBox12.TabIndex = 14
        Me.TextBox12.Text = "TextBox12"
        '
        'TextBox11
        '
        Me.TextBox11.Location = New System.Drawing.Point(232, 72)
        Me.TextBox11.Name = "TextBox11"
        Me.TextBox11.Size = New System.Drawing.Size(40, 20)
        Me.TextBox11.TabIndex = 13
        Me.TextBox11.Text = "TextBox11"
        '
        'TextBox10
        '
        Me.TextBox10.Location = New System.Drawing.Point(184, 72)
        Me.TextBox10.Name = "TextBox10"
        Me.TextBox10.Size = New System.Drawing.Size(40, 20)
        Me.TextBox10.TabIndex = 12
        Me.TextBox10.Text = "TextBox10"
        '
        'TextBox9
        '
        Me.TextBox9.Location = New System.Drawing.Point(136, 72)
        Me.TextBox9.Name = "TextBox9"
        Me.TextBox9.Size = New System.Drawing.Size(40, 20)
        Me.TextBox9.TabIndex = 11
        Me.TextBox9.Text = "TextBox9"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(384, 32)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(48, 16)
        Me.Label3.TabIndex = 9
        Me.Label3.Text = "Average"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(200, 31)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96, 16)
        Me.Label2.TabIndex = 7
        Me.Label2.Text = "Test Scores"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'txtTest5
        '
        Me.txtTest5.Location = New System.Drawing.Point(328, 48)
        Me.txtTest5.Name = "txtTest5"
        Me.txtTest5.Size = New System.Drawing.Size(40, 20)
        Me.txtTest5.TabIndex = 6
        Me.txtTest5.Text = "TextBox6"
        '
        'txtTest4
        '
        Me.txtTest4.Location = New System.Drawing.Point(280, 48)
        Me.txtTest4.Name = "txtTest4"
        Me.txtTest4.Size = New System.Drawing.Size(40, 20)
        Me.txtTest4.TabIndex = 5
        Me.txtTest4.Text = "TextBox5"
        '
        'txtTest3
        '
        Me.txtTest3.Location = New System.Drawing.Point(232, 48)
        Me.txtTest3.Name = "txtTest3"
        Me.txtTest3.Size = New System.Drawing.Size(40, 20)
        Me.txtTest3.TabIndex = 4
        Me.txtTest3.Text = "TextBox4"
        '
        'txtTest2
        '
        Me.txtTest2.Location = New System.Drawing.Point(184, 48)
        Me.txtTest2.Name = "txtTest2"
        Me.txtTest2.Size = New System.Drawing.Size(40, 20)
        Me.txtTest2.TabIndex = 3
        Me.txtTest2.Text = "TextBox3"
        '
        'txtTest1
        '
        Me.txtTest1.Location = New System.Drawing.Point(136, 48)
        Me.txtTest1.Name = "txtTest1"
        Me.txtTest1.Size = New System.Drawing.Size(40, 20)
        Me.txtTest1.TabIndex = 2
        Me.txtTest1.Text = "TextBox2"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 32)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(104, 16)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Name"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(16, 48)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(104, 20)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = "TextBox1"
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2, Me.MenuItem3})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFileOpen, Me.mnuFileSaveAs, Me.MenuItem6, Me.mnuFilePrint, Me.mnuExit})
        Me.MenuItem1.Text = "&File"
        '
        'mnuFileOpen
        '
        Me.mnuFileOpen.Index = 0
        Me.mnuFileOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO
        Me.mnuFileOpen.Text = "&Open File..."
        '
        'mnuFileSaveAs
        '
        Me.mnuFileSaveAs.Index = 1
        Me.mnuFileSaveAs.Shortcut = System.Windows.Forms.Shortcut.CtrlS
        Me.mnuFileSaveAs.Text = "&Save As"
        '
        'MenuItem6
        '
        Me.MenuItem6.Index = 2
        Me.MenuItem6.Text = "-"
        '
        'mnuFilePrint
        '
        Me.mnuFilePrint.Index = 3
        Me.mnuFilePrint.Shortcut = System.Windows.Forms.Shortcut.CtrlP
        Me.mnuFilePrint.Text = "&Print Report"
        '
        'mnuExit
        '
        Me.mnuExit.Index = 4
        Me.mnuExit.Shortcut = System.Windows.Forms.Shortcut.CtrlQ
        Me.mnuExit.Text = "E&xit"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 1
        Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuReport, Me.mnuReportDisplay})
        Me.MenuItem2.Text = "&Report"
        '
        'mnuReport
        '
        Me.mnuReport.Index = 0
        Me.mnuReport.Text = "&Report Data"
        '
        'mnuReportDisplay
        '
        Me.mnuReportDisplay.Index = 1
        Me.mnuReportDisplay.Text = "&Report Display"
        '
        'MenuItem3
        '
        Me.MenuItem3.Index = 2
        Me.MenuItem3.Text = "&Help"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(376, 240)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(80, 32)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Calculate Averages"
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(16, 304)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(448, 199)
        Me.ListBox1.TabIndex = 2
        '
        'frmTestScores
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(472, 537)
        Me.Controls.Add(Me.ListBox1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.mnuReportData)
        Me.Menu = Me.MainMenu1
        Me.Name = "frmTestScores"
        Me.Text = "Student Test Scores"
        Me.mnuReportData.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    'Dim studentName(maxSubscript) As String
    'Dim test
    Structure StudentRecord
        Dim studentName As String
        Dim testScores() As Single
        Dim averageTestScore As Single
    End Structure
    'array upper subscript
    'Const maxSubscript As Integer = 5
    'array of StudentRe
    Dim students(5) As StudentRecord
    Private Sub initArrays()
        Dim i As Integer

        'students(0).studentName = " "
        For i = 0 To 5
            ReDim students(i).testScores(4)
            students(i).studentName = " "

            students(i).studentName = " "
            students(i).testScores(0) = ""
            students(i).testScores(1) = ""
            students(i).testScores(2) = ""
            students(i).testScores(3) = ""
            students(i).testScores(4) = ""

        Next i
    End Sub

   
    Private Sub mnuReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuReport.Click
        'promt the user for Test Scores data
        Dim i As Integer
        Dim j As Integer
        'get test scores for each student
        For i = 0 To 5
            ReDim students(i).testScores(4)
            students(i).studentName = InputBox("Enter the name " & students(i).studentName, "Student Name")

            ' For j = 0 To 4
            students(i).testScores(0) = Val(InputBox("Enter the test Scores" & i + 1, "Student Scores"))
            students(i).testScores(1) = Val(InputBox("Enter the test Scores" & i + 2, "Student Scores"))
            students(i).testScores(2) = Val(InputBox("Enter the test Scores" & i + 3, "Student Scores"))
            students(i).testScores(3) = Val(InputBox("Enter the test Scores" & i + 4, "Student Scores"))
            students(i).testScores(4) = Val(InputBox("Enter the test Scores" & i + 5, "Student Scores"))

            'Next j
        Next i
    End Sub

    Private Sub mnuReportDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuReportDisplay.Click
        'calculate and display the average for each student
        Dim i As Integer
        Dim total As Integer = 0 ' Initialize accumulator
        Dim average As Single
        For i = 0 To (students(i).testScores.Length - 1)

            'calculate the total
            total += students(i).testScores(i)
            average = total / students(i).testScores.Length
            ListBox1.Items.Add("Student names: " & students(i).studentName.ToString)
            ListBox1.Items.Add("Test1: " & students(i).testScores(0))
            ListBox1.Items.Add("Test2: " & students(i).testScores(1))
            ListBox1.Items.Add("Test3: " & students(i).testScores(2))
            ListBox1.Items.Add("Test4: " & students(i).testScores(3))
            ListBox1.Items.Add("Test5: " & students(i).testScores(4))
            'average = total / students(i).testScores.Length
            ListBox1.Items.Add("Average: " & students(i).averageTestScore)
Next
     
    End Sub

    Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOpen.Click
        'let the user select a file to open, and pass the
        'selected file name to the ReadFile procedure
        With ofdOpenFile
            .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
            .Title = "Select a File to Open"
            If .ShowDialog = DialogResult.OK Then
                If .FileName <> "" Then
                    readfile(.FileName)
                Else
                    MessageBox.Show("No file selected.", "Error")
                End If
            End If

        End With
    End Sub

    Private Sub mnuFileSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileSaveAs.Click
        'let the user select or enter a file name to save the data
        ' pass the file name to the Savefile procedure
        With sfdSaveFile
            .Filter = "Text Files (*.txt) | *.txt|All Files (*.*) | *.*"
            .Title = "Save File As"
            If .ShowDialog = DialogResult.OK Then
                If .FileName <> "" Then
                    SaveFile(.FileName)
                Else
                    MessageBox.Show("File not saved.", "Error")

                End If
            End If
        End With
    End Sub
    Sub ReadFile(ByVal filename As String)
        'Read the contents of the specified file
        Dim inputFile As System.IO.StreamReader
        Dim count As Integer = 0 'loop counter
        'open the file
        inputFile = System.IO.File.OpenText(filename)
        'read the data
        Do While (inputFile.Peek <> -1) And (count <= 5)
            students(count).testScores(4) = inputFile.ReadLine
            count += 1
        Loop
        'close the file
        inputFile.Close()

    End Sub
    Sub SaveFile(ByVal filename As String)
        'Save the contents of the students array
        Dim outputFile As System.IO.StreamWriter
        Dim count As Integer 'loop counter
        'open the file
        outputFile = System.IO.File.CreateText(filename)
        'Save the data
        For count = 0 To 5
            outputFile.WriteLine(students(count).testScores(4))
        Next
        'close the file
        outputFile.Close()

    End Sub
    Private Sub mnuFilePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFilePrint.Click
        'call the Print method to start printing
        pdPrint.PrinterSettings()


    End Sub
    Private Sub pdPrint_printpage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdPrint.printpage
        'this procedure prints the student Records
        Dim count As Integer
        Dim testScores(5) As Single
        Dim vertPos As Integer

        'print the report header
        e.Graphics.DrawString("Student Scores" & "Student Report", New Font("Courier New", 10, FontStyle.Bold), Brushes.Black, 150, 10)
        e.Graphics.DrawString("Date and Time: " & Now.ToString, New Font("Courier New", 10, FontStyle.Bold), Brushes.Black, 10, 38)
        'set the vertical position for the firat item
        vertPos = 80
        'print test Score data
        For count = 0 To 5
            e.Graphics.DrawString(string.format(students(count).studentName , students(count).testscores(count)), new font ("Courier New", 10, fonstyle.regular), brushes.blace, 10, vertpos))

            vertPos += 1
        Next
        e.Graphics.DrawString("Average Test Scores: " &

    End Sub
End Class

Here are all of the my works, I have design this but I am still get alots errors in my program, I declared some variables but some doesn't allow me to use! Could anyone help me to find out my mistakes and give me the best solution! The form also have some textbox that will contain the test score and name !
Anyhelp will appriciate!
Thanks
0
Comment
Question by:leeyoung
  • 3
  • 2
7 Comments
 
LVL 4

Expert Comment

by:krznpsk
ID: 9850869
'Dim studentName(maxSubscript) As String
    'Dim test


^^ you have several of your variables commented out.  Is this intentional?
0
 

Author Comment

by:leeyoung
ID: 9855298
No, in this my program, I want to display them in txtbox and label, This is not intentional! I wonder if I get the big mistakes in my program or not, I want to make better enhancement in this, It is not important to output or display!
thanks krznpsk for comment! Could you tell me what wrong in my program? give me solution!
0
 
LVL 4

Expert Comment

by:krznpsk
ID: 9863074
Okay, I will point out a few things wrong with your code.

In Private Sub initArrays():
     students(i).testScores(0) = ""
     ^^ "" is a string, and testScores() is an array of Singles.  You cannot cast a string to a Single.  This line should be:
     students(i).testScores(0) = 0

In Private Sub pdPrint_printpage:
     e.Graphics.DrawString("Average Test Scores: " &
     ^^ you need to close your parentheses.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:leeyoung
ID: 9863326
yeah, Thanks! In my program when I calculate the average test scores for every student but I cannot calculate that, when I input student name, test scores of one student and average always equal to 0!
E.x:
Lee
98
56
56
56
45
Average: 0
Ba
34
34
34
34
43
Average: 0
.....
How can I resolve this problem? does it have anything that you point out more my errors?
0
 
LVL 4

Accepted Solution

by:
krznpsk earned 20 total points
ID: 9863461
Let's take a look at this block:

For i = 0 To (students(i).testScores.Length - 1)
            'calculate the total
            total += students(i).testScores(i)
            average = total / students(i).testScores.Length
            ListBox1.Items.Add("Student names: " & students(i).studentName.ToString)
            ListBox1.Items.Add("Test1: " & students(i).testScores(0))
            ListBox1.Items.Add("Test2: " & students(i).testScores(1))
            ListBox1.Items.Add("Test3: " & students(i).testScores(2))
            ListBox1.Items.Add("Test4: " & students(i).testScores(3))
            ListBox1.Items.Add("Test5: " & students(i).testScores(4))
            'average = total / students(i).testScores.Length
            ListBox1.Items.Add("Average: " & students(i).averageTestScore)
      '^^^^^ THE PROBLEM IS RIGHT HERE!  You have never set a value for averageTestScore. ^^^^^
Next

Try changing it to this:

For Each currentStudent as StudentRecord in students
     Dim total as Integer = 0
     Dim myCounter as Integer = 0
     For Each currentScore as Single in currentStudent.testScores
          ListBox1.Items.Add("Test " & (myCounter) & ": " & currentScore)
          total += currentScore
          myCounter += 1
     Next currentScore
     Dim currentStudentAverage as Single = total / currentStudent.testScores.Length
     currentStudent.averageTestScore = currentStudentAverage
     ListBox1.Items.Add("Average: " & currentStudent.averageTestScore)
Next currentStudent
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10279772
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: krznpsk {http:#9863461}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now