dcsimg
Results 1 to 15 of 15

Thread: [RESOLVED] Listbox and counter errors...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Location
    Wilmington,NC
    Posts
    72

    Resolved [RESOLVED] Listbox and counter errors...

    So my program is suposed to prompt me for 5 integers. these 5 will be added together and produce an average I also need to put a Letter grade, in a label for the average of the 5 numbers.(this idk how to do)
    these 5 must be between 0-100 and I'm just lost...i built a program like this before with weight loss but I'm aslo smashed with python can you guys help me out with where some errors are? I'm just crammed and i keep confusing the 2 languages that i'm just now learning.
    Code:
    'Program Name: Grade Book
    'Dev: Bryan Cruse
    'Date:11/24/15
    
    Option Strict On
    
    
    
    
    Public Class frmGradeBook
        Dim intGrades As Integer
        Dim IntNumberOFentries As Integer = 1
        Dim StrGrades As String
        Dim decFinalGrades As Decimal
        Dim intMaxNumberOfEntries As Integer = 5
        Dim StrInputMessage As String = "Please enter your grade"
        Dim StrInputHeading As String = "Grade Book"
        Dim StrNormalMessage As String
    
    
    
        Private Sub mnuExitProgramItem_Click(sender As Object, e As EventArgs) Handles mnuExitProgramItem.Click
            Close()
        End Sub
    
        Private Sub mnuClearGradesItem_Click(sender As Object, e As EventArgs) Handles mnuClearGradesItem.Click
            lstGrades.Items.Clear()
    
        End Sub
    
        Private Sub btnEnterGrades_Click(sender As Object, e As EventArgs) Handles btnEnterGrades.Click
    
            Dim strCancelClicked As String = ""
            StrGrades = InputBox("Please Enter your grades", "Grade Book", )
    
    
            Do Until IntNumberOFentries > intMaxNumberOfEntries Or StrGrades = strCancelClicked
    
    
              
    
                If IsNumeric(StrGrades) Then
                    intGrades = CInt(Convert.ToDecimal(StrGrades))
    
                    If intGrades > 100 Then
                        MsgBox("Please enter a valid grade.", MsgBoxStyle.Exclamation, "Grade Book")
                        If intGrades > 0 Then
                        Else : MsgBox("You entered a non usable number", , "Input Error")
                        End If
                        lstGrades.Items.Add(intGrades)
                        decFinalGrades += intGrades
                        IntNumberOFentries += 1
                        StrInputMessage = strNormalMessage
                        If IntNumberOFentries >= intMaxNumberOfEntries Then
                            StrGrades = InputBox(StrInputHeading & IntNumberOFentries, StrInputHeading, " ")
                        End If
                    End If
                End If
            Loop
    
            lstGrades.Items.Add(intGrades)
    
            If IntNumberOFentries <= 5 Then
                lblScore.Visible = True
                decFinalGrades = CDec(intGrades / 7)
                If decFinalGrades <= 68 Then
                    lblGrade.Text = "F"
                End If
            End If
    
                End While
    
    
        End Sub
    End Class
    Last edited by ItsBryanTho; Dec 14th, 2015 at 01:51 PM. Reason: clarity

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,594

    Re: Listbox and counter errors...

    Didn't we answer this question last week?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Location
    Wilmington,NC
    Posts
    72

    Re: Listbox and counter errors...

    idk, in two weeks i've destroyed a tb HD and a laptop. so I dont have my other programs to help me remember what to do or any of this one except this hatchet job. I'm re writing now, but I didn't know how to assign a number which would be the final grade to a letter. i imagine it's something simple with ranges and i know exporting it to a label will be easy.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Location
    Wilmington,NC
    Posts
    72

    Re: Listbox and counter errors...

    Code:
     StrNormalMessage = InputBox(StrInputMessage & IntNumberOFentries, StrInputHeading, "")
    
            Do Until IntNumberOFentries > intMaxNumberOfEntries
                If IsNumeric(StrGrades) Then
                    decGrades = Convert.ToDecimal(StrGrades)
                    lstGrades.Items.Add(decGrades)
                    If decGrades < 0 Then
                        MsgBox("Please enter a positive number", MsgBoxStyle.Critical, "Grade Book")
                        If decGrades >= 100 Then
                            MsgBox("Please enter a correct value", MsgBoxStyle.Exclamation, "Grade Book")
                        End If
                    End If
    
                End If
    
    
                If IntNumberOFentries <= intMaxNumberOfEntries Then
                    lblScore.Visible = True
                    decFinalGrades = decGrades / IntNumberOFentries
                    lblScore.Text = decFinalGrades.ToString
    
                End If
            Loop
    i have NO idea why this isn't working it's worked like this before. I did use just if and end if instead of else and else in my validation of entered data

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Location
    Wilmington,NC
    Posts
    72

    Re: Listbox and counter errors...

    i've fixed and there is an error in this
    Code:
     Do Until intMaxNumberOfEntries < 6
                If IsNumeric(StrGrades) Then
                    decGrades = Convert.ToDecimal(StrGrades)
                    If decGrades < 0 Then
                        lstGrades.Items.Add(StrGrades)
                        decFinalGrades += decGrades
                        StrInputMessage = StrNormalMessage
                    Else
                        MsgBox("Please enter a positive number", MsgBoxStyle.Critical, "Grade Book")
                    End If
                    If decGrades >= 100 Then
                        MsgBox("Please enter a correct value", MsgBoxStyle.Exclamation, "Grade Book")
                    End If
                End If
            Loop
            If IntNumberOFentries <= intMaxNumberOfEntries Then
                lblScore.Visible = True
                decFinalGrades = decGrades / intMaxNumberOfEntries
                lblScore.Text = decFinalGrades.ToString
    
            End If
    it won't allow only 5 entries. stops me at one.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,594

    Re: Listbox and counter errors...

    Do Until intMaxNumberOfEntries < 6

    Try Do While...

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,594

    Re: Listbox and counter errors...

    Code:
    Do While IntNumberOFentries < 6
        Dim strGrades As String = InputBox("Enter a grade")
        If IsNumeric(strGrades) Then
            decGrades = Convert.ToDecimal(strGrades)
            If decGrades > 0 AndAlso decGrades < 100 Then
                IntNumberOFentries += 1
                lstGrades.Items.Add(strGrades)
                decFinalGrades += decGrades
                StrInputMessage = StrNormalMessage
            ElseIf decGrades <= 0 Then
                MsgBox("Please enter a positive number", MsgBoxStyle.Critical, "Grade Book")
            ElseIf decGrades >= 100 Then
                MsgBox("Please enter a correct value", MsgBoxStyle.Exclamation, "Grade Book")
            End If
        End If
    Loop
    lblScore.Visible = True
    decFinalGrades = decGrades / intMaxNumberOfEntries
    lblScore.Text = decFinalGrades.ToString

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Location
    Wilmington,NC
    Posts
    72

    Re: Listbox and counter errors...

    works great, do you know a easy way to find out what range it would fall under like this?A: 92-100, B: 84-91, C: 76-83, D: 68-75, F: Below 68 and it'd be rounded up at .5 i'd need to convert from a decimal to a character right? ughh
    Thank you though for the above that helps out very much.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Location
    Wilmington,NC
    Posts
    72

    Re: Listbox and counter errors...

    i like my while loops....they do EVERYTHING

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,594

    Re: Listbox and counter errors...

    Code:
    Dim gradeLetter as String
    Select Case aNumber
        Case < 68
            gradeLetter = "F"
        Case <= 75
            gradeLetter = "D"
        Case <= 83
            gradeLetter = "C" 
        Case <= 91
            gradeLetter = "B"
        Case <= 100
            gradeLetter = "A"
    End Select

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Location
    Wilmington,NC
    Posts
    72

    Re: Listbox and counter errors...

    that worked, but it's got some kind of bug in there that asks me for a value the first time and then doesnt display it. Also by looking at this does my math logic look correct? This is full code
    Code:
    'Program Name: Grade Book
    'Dev: Bryan Cruse
    'Date:11/24/15
    
    Option Strict On
    
    
    
    
    Public Class frmGradeBook
        Dim intGrades As Integer
        Dim IntNumberOFentries As Integer = 1
        Dim StrGrades As String
        Dim decFinalGrades As Decimal
        Dim intMaxNumberOfEntries As Integer = 5
        Dim StrInputMessage As String = "Please enter your grade"
        Dim StrInputHeading As String = "Grade Book"
        Dim StrNormalMessage As String
        Dim decGrades As Decimal
        Dim StrLetterGrade As String
    
    
    
    
        Private Sub mnuExitProgramItem_Click(sender As Object, e As EventArgs) Handles mnuExitProgramItem.Click
            Close()
        End Sub
    
        Private Sub mnuClearGradesItem_Click(sender As Object, e As EventArgs) Handles mnuClearGradesItem.Click
            lstGrades.Items.Clear()
            lblGrade.Visible = False
            lblScore.Visible = False
            btnEnterGrades.Enabled = True
    
        End Sub
    
        Private Sub btnEnterGrades_Click(sender As Object, e As EventArgs) Handles btnEnterGrades.Click
            StrNormalMessage = InputBox(StrInputMessage & IntNumberOFentries, StrInputHeading, "")
    
            
            Do While IntNumberOFentries < 6
                Dim strGrades As String = InputBox("Enter a grade")
                If IsNumeric(strGrades) Then
                    decGrades = Convert.ToDecimal(strGrades)
                    If decGrades > 0 AndAlso decGrades < 100 Then
                        IntNumberOFentries += 1
                        lstGrades.Items.Add(strGrades)
                        decFinalGrades += decGrades
                        StrInputMessage = StrNormalMessage
                    ElseIf decGrades <= 0 Then
                        MsgBox("Please enter a positive number", MsgBoxStyle.Critical, "Grade Book")
                    ElseIf decGrades >= 100 Then
                        MsgBox("Please enter a correct value", MsgBoxStyle.Exclamation, "Grade Book")
                    End If
                End If
            Loop
            Dim StrgradeLetter As String
            Select Case decGrades
                Case Is < 68
                    StrgradeLetter = "F"
                Case Is <= CDec(66.5)
                    StrgradeLetter = "D"
                Case Is <= CDec(75.5)
                    StrgradeLetter = "C"
                Case Is <= CDec(83.1)
                    StrgradeLetter = "B"
                Case Is <= CDec(91.5)
                    StrgradeLetter = "A"
            End Select
            lblScore.Visible = True
            decFinalGrades = decGrades / (intMaxNumberOfEntries - 1)
            lblScore.Text = decFinalGrades.ToString
            lblGrade.Text = StrgradeLetter
    
    
    
    
    
    
    
    
    
        End Sub
    End Class

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,594

    Re: Listbox and counter errors...

    Every time you call InputBox it will prompt for input.
    You need to look at the Select Case again. Grade D will never be assigned. Also You are probably meant to use Select Case avgGrade (decFinalGrades / 5)

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Location
    Wilmington,NC
    Posts
    72

    Re: Listbox and counter errors...

    That does work...the input box needs to INSIDE my loops so I'll be prompted everytime. I fixed the math since i have my loop right now. BUT how would i output the select case to a label? I've read everywhere and can't figure it out. It'd be putting that string into lblGrade(and i dont know why i tried lblgrade.text) so Idk how to do it to be honest.
    Code:
    Select Case decGrades
                Case Is < 68
                    StrgradeLetter = "F"
                Case Is <= CDec(66.5)
                    StrgradeLetter = "D"
                Case Is <= CDec(75.5)
                    StrgradeLetter = "C"
                Case Is <= CDec(83.1)
                    StrgradeLetter = "B"
                Case Is <= CDec(91.5)
                    StrgradeLetter = "A"
    thats what needs to be in lblGrade, but it can't take strings -.-

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Location
    Wilmington,NC
    Posts
    72

    Re: Listbox and counter errors...

    Quote Originally Posted by .paul. View Post
    Every time you call InputBox it will prompt for input.
    You need to look at the Select Case again. Grade D will never be assigned. Also You are probably meant to use Select Case avgGrade (decFinalGrades / 5)
    thanks my logic was off

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Location
    Wilmington,NC
    Posts
    72

    Re: Listbox and counter errors...

    my math is wrong also. If i enter a 98 5 times I end up with a number like x.xx ??

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width