Visual basic help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Visual basic help

  1. #1
    Join Date
    Jan 2014
    Posts
    1

    Visual basic help

    hi everyone,
    i really need some help with a VB project im doing, im sure its something simple but i just cant find the problem.


    Attachment 32313
    whats happening here is im clicking the display student grade button which should be displaying the students name, their grade and mark which id read in from a text file. but all that is happening is the rest of the text boxes are displaying the average, highest and lowest based on the students marks, which means the student list box must be there but its just not displaying itself



    Attachment 32315
    this is what happens after i click the placement button which works perfectly. this list box also needs to take into account the student list box data i.e mark, grade etc in order to display correctly. no matter what i try i just cant get the student list box to populate with the data.



    heres a list of the code i have but once again there are no errors shown so im pretty stumped
    Code:
    Public Class StudentGrade
        Dim answerkey() As String = IO.File.ReadAllLines("answerkey.txt")
        Structure Student
            Dim student As String
            Dim answer As String
            Dim mark As String
            Dim grade As String
            Dim order As String
        End Structure 'creates a structure to hold variables
        Dim Test() As Student
        Dim stanswers() As String
    
        Private Sub rbtTest1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtTest1.CheckedChanged
            If rbtTest2.Checked = True Then
                answerkey = IO.File.ReadAllLines("answerkey2.txt") ' reads in the answerkey2.txt into answerkey text box
            Else
                answerkey = IO.File.ReadAllLines("answerkey.txt") ' reads in answerkey.txt into answerkey text box if not checked
            End If
            txtAverage.Text = Nothing
            txthighestMark.Text = Nothing
            txtLowestMark.Text = Nothing
            lstvStudent.Items.Clear()
            lstPlacement.Items.Clear()
            txtAnswerKey.Text = answerkey(0)
            ' This instructs the program to read the student answers text file into the 'stanswers' array
            stanswers = IO.File.ReadAllLines("stanswers.txt")
    
            'Changes the contents of the answerkey text file to upper case
            '  txtanswer.Text = answerkey(0).ToUpper
    
            If rbtTest1.Checked = True Then
                stanswers = IO.File.ReadAllLines("stanswers.txt") 'compares the answerkey to student answers 
            Else
                stanswers = IO.File.ReadAllLines("stanswers2.txt")
            End If
            lstvStudent.Items.Clear()
            lstPlacement.Items.Clear()
    
        End Sub
    
    
        Private Sub btnStudentGrades_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStudentGrades.Click
            'Array1 is declared to read in the text file's contents
            Dim Array1() As String = stanswers
    
            'counts the number of boxes within the 'array1' array containing the student answers text file
            Dim n As Integer = Array1.Count - 1
    
            'redimensions the students structure array with the same number of boxes as 'array1'
            ReDim Test(n)
    
            'data is an array that will hold two data packets from text file (student name and answer)
            Dim packet() As String
            For i As Integer = 0 To n  ' 
    
                packet = Array1(i).Split(","c)
                Test(i).student = packet(0)
                Test(i).answer = packet(1)
    
            Next
            'Setup to hold student marks
            Dim mark(n) As Integer
    
            Dim strSub1 As String
            Dim strSub2 As String = answerkey(0)
    
            ' This next  section compares the students answers with the answer key and increases
            ' the count by 1 everytime a correct answer is found.
            For i As Integer = 0 To n 'length of the arrays 
                Dim counter As Integer = 0
                strSub1 = Test(i).answer.ToUpper
                For j As Integer = 0 To strSub1.Length - 1
                    If strSub1.Substring(j, 1) = strSub2.Substring(j, 1) Then
                        counter += 1
                    End If
    
                Next
                ' parameters put in place to decide both grade and placement
                'The total score achieved by the student will be relative to their average placement
                mark(i) = counter
                Test(i).mark = CStr(mark(i))
    
                If CDbl(Test(i).mark) <= 5 Then
                    Test(i).grade = "F"
                    Test(i).order = "Below Average"
                ElseIf CDbl(Test(i).mark) = 6 Then
                    Test(i).grade = "D"
                    Test(i).order = "Below Average"
                ElseIf CDbl(Test(i).mark) = 7 Then
                    Test(i).grade = "C"
                    Test(i).order = "Average"
    
                ElseIf CDbl(Test(i).mark) = 8 Then
                    Test(i).grade = "B"
                    Test(i).order = "Above Average"
                Else
                    Test(i).grade = "A"
                    Test(i).order = "Above Average"
    
                End If
    
            Next
            ' calculates the low, high and average scores and places in corresponding text box
            txtAverage.Text = CStr(mark.Average)
            txthighestMark.Text = CStr(mark.Max)
            txtLowestMark.Text = CStr(mark.Min)
            lstPlacement.Items.Clear()
    
            For i As Integer = 0 To n
                lstPlacement.Items.Add(Test(i).student & vbTab & Test(i).mark & vbTab & Test(i).grade)
            Next
            lstPlacement.Items.Clear()
    
        End Sub
    
    
        Private Sub btnPlacement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlacement.Click
    
            lstPlacement.Items.Clear()
    
            For i As Integer = 0 To Test.Length - 1
                lstPlacement.Items.Add(Test(i).order)
            Next
    
        End Sub
    
    
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
            Application.Exit()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
            rbtTest1.Checked = Nothing
            rbtTest2.Checked = Nothing
            txtAnswerKey.Clear()
            txtAverage.Clear()
            txthighestMark.Clear()
            txtLowestMark.Clear()
            lstvStudent.Items.Clear()
            lstPlacement.Items.Clear() 'wipes all remaining data from the form 
        End Sub
    
        Private Sub StudentGrade_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    End Class

    any help would be greatly appreciated. thanks everyone
    Last edited by DataMiser; February 1st, 2014 at 11:19 AM. Reason: added code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,987

    Re: Visual basic help

    Go back and edit your post to change:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Application.Exit()
    End Sub

    into this, using the # tag:

    Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
         Application.Exit()
    End Sub
    So we can see what you are trying to do. You can also attach an image to your post
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center