1 Replies - 207 Views - Last Post: 28 February 2019 - 07:54 AM Rate Topic: -----

#1 Floki   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-February 19

Using case to Allocate student Grade

Posted 28 February 2019 - 07:04 AM

Public Sub Scores()
        Dim Score(7) As Integer
        Score(0) = TextBox3.Text
        Score(1) = TextBox4.Text
        Score(2) = TextBox5.Text
        Score(3) = TextBox6.Text
        Score(4) = TextBox7.Text
        Score(5) = TextBox8.Text
        Score(6) = TextBox9.Text
        Score(7) = TextBox10.Text

        Dim total As Double
        Dim avg As Double
        For counter As Integer = 0 To 7
            total += Score(counter)
        Next
        TextBox19.Text = total

        avg = total / Score.Length
        TextBox20.Text = avg       [i]'I'm good upto here,I have been able to get the Total marks and average.[/i] 

        Select Case Score
            Case 1
                If Score < 0 Then       'Problem arises here where the "less than" sign is. The error indicated is "The operator 
                    TextBox18.Text = ("Invalid ")          'is not defined for types '1-dimensional array of Integer and integer'"
                ElseIf Score < 40 Then
                    TextBox18.Text = ("Fail")
                ElseIf Score < 49 AndAlso Score > 39 Then
                    TextBox18.Text = ("D")
                ElseIf Score < 59 AndAlso Score > 49 Then
                    TextBox18.Text = ("C")
                ElseIf Score < 69 AndAlso Score > 59 Then
                    TextBox18.Text = ("B")
                ElseIf Score > 70 Then
                    TextBox18.Text = ("A")
                End If
            Case 2
                If Score < 0 Then
                    TextBox17.Text = ("Invalid ")
                ElseIf Score < 40 Then
                    TextBox17.Text = ("Fail")
                ElseIf Score < 49 AndAlso Score > 39 Then
                    TextBox17.Text = ("D")
                ElseIf Score < 59 AndAlso Score > 49 Then
                    TextBox17.Text = ("C")
                ElseIf Score < 69 AndAlso Score > 59 Then
                    TextBox17.Text = ("B")
                ElseIf Score > 70 Then
                    TextBox17.Text = ("A")
                End If
        End Select
    End Sub



I have searched for examples that resembles my quiz but couldn't find such. Even youtube tutorials have no videos of select [case] with If control incorporated within the code.
The signs symbols are all underlined.
Kindly help.

Is This A Good Question/Topic? 0
  • +

Replies To: Using case to Allocate student Grade

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14854
  • View blog
  • Posts: 59,272
  • Joined: 12-June 08

Re: Using case to Allocate student Grade

Posted 28 February 2019 - 07:54 AM

Does your switch make sense using 'Score'? I mean is score really going to be 1 or 0?

Perhaps use a range with the key word 'to'.

https://docs.microso...-case-statement
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1