[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Case statement fails case when it is not supposed to

Posted on 2004-09-13
15
Medium Priority
?
195 Views
Last Modified: 2010-04-23
I have setup a case statement and the statement is bypassed when it is not supposed to be bypassed.  I have checked the data I am compairing for and it does meet the criteria.  When I debug and step through the code, it hits Case grade=9 and then steps to the case grade = 10.  The actual data is grade="9" when I look at the local variables.  I have tried useing the val command to convert it to a value but this did not help.  Can someone point out what I may be missing.  Here is the code.

Thanks
Kenny


'Calculate Objective Scores Totals

            Select Case grade

Case grade = "9"

                    readingEla9AvailableObj1 = 9
                    readingEla9AvailableObj2 = 15
                    readingEla9AvailableObj3 = 18
                    readingEla9TotalAvailable = 42

                    math9AvailableObj1 = 5
                    math9AvailableObj2 = 5
                    math9AvailableObj3 = 5
                    math9AvailableObj4 = 5
                    math9AvailableObj5 = 4
                    math9AvailableObj6 = 4
                    math9AvailableObj7 = 4
                    math9AvailableObj8 = 6
                    math9AvailableObj9 = 5
                    math9AvailableObj10 = 9
                    math9TotalAvailable = 52

                    readingElaObj91ObjectiveGrade = CalculatePF(readingEla9AvailableObj1, readingElaObjScoresArray(1))
                    readingElaObj92ObjectiveGrade = CalculatePF(readingEla9AvailableObj2, readingElaObjScoresArray(2))
                    readingElaObj93ObjectiveGrade = CalculatePF(readingEla9AvailableObj3, readingElaObjScoresArray(3))

                    MathObj91ObjectiveGrade = CalculatePF(math9AvailableObj1, mathObjScoresArray(1))
                    MathObj92ObjectiveGrade = CalculatePF(math9AvailableObj2, mathObjScoresArray(2))
                    MathObj93ObjectiveGrade = CalculatePF(math9AvailableObj3, mathObjScoresArray(3))
                    MathObj94ObjectiveGrade = CalculatePF(math9AvailableObj4, mathObjScoresArray(4))
                    MathObj95ObjectiveGrade = CalculatePF(math9AvailableObj5, mathObjScoresArray(5))
                    MathObj96ObjectiveGrade = CalculatePF(math9AvailableObj6, mathObjScoresArray(6))
                    MathObj97ObjectiveGrade = CalculatePF(math9AvailableObj1, mathObjScoresArray(7))
                    MathObj98ObjectiveGrade = CalculatePF(math9AvailableObj2, mathObjScoresArray(8))
                    MathObj99ObjectiveGrade = CalculatePF(math9AvailableObj3, mathObjScoresArray(9))
                    MathObj910ObjectiveGrade = CalculatePF(math9AvailableObj4, mathObjScoresArray(10))

                    Try
                        Dim objConnection6 As SqlConnection = New SqlConnection("server=(local);database=FBISD-TAKS;user id=sa;password=pa55word")
                        Dim objCommand6 As SqlCommand = New SqlCommand
                        objCommand6.Connection = objConnection6
                        objCommand6.CommandText = "Insert Into objectivesCorrect " & "(admDate) " & _
                                "VALUES(@oadmDate)"
                        objCommand6.Parameters.Add("@oadmDate", SqlDbType.DateTime, 10).Value = madmDate
                        objCommand6.Parameters.Add("@ostudentId", SqlDbType.Int, 10).Value = studentId
                        objCommand6.Parameters.Add("@oteacherId", SqlDbType.Int, 8).Value = teacher1
                        objConnection6.Open()
                        Dim kenny As String
                        kenny = objCommand6.CommandText
                        MsgBox(kenny)
                        objCommand6.ExecuteNonQuery().ToString()
                        objConnection6.Close()

                    Catch ex As Exception
                        MsgBox(ex.ToString())

                    End Try




                Case grade = 10
                    readingEla10AvailableObj1 = 8
                    readingEla10AvailableObj2 = 11
                    readingEla10AvailableObj3 = 18
                    readingEla10AvailableObj6 = 20
                    readingEla10TotalAvailable = 57

                    math10AvailableObj1 = 5

                    ..................etc



               End Select

0
Comment
Question by:kwh3856
  • 8
  • 7
15 Comments
 
LVL 8

Expert Comment

by:wguerram
ID: 12047554
Try placing a msgbox just before the Select case

Msgbox (grade)

if the variable is numeric

Msgbox (grade.tostring)

just to see what is the value.

How do you obtain the value for the grade variable?
can you post the code?
0
 

Author Comment

by:kwh3856
ID: 12047608
I will try that and let you know.  Here is the code where I get the grade.

objStreamReader = New StreamReader("C:\fbisd\t178914a.dat")
        strLine = objStreamReader.ReadLine
        Do While Not strLine Is Nothing
            admDate = Mid(strLine, 1, 4)
            admDate = admDate.Substring(0, 2) & "/01/20" & admDate.Substring(2)
            madmDate = admDate
            grade = Val(Mid(strLine, 5, 2))


0
 
LVL 8

Expert Comment

by:wguerram
ID: 12047644
What type of value is the variable grade?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kwh3856
ID: 12047645
The message box showed a value of 9.  It was not in quotes. Yet when you look at the local varibles for grade...it show it in quotes
0
 

Author Comment

by:kwh3856
ID: 12047663
I read the grade in as a string variable and then covert it to a numeric value.  It is actually the grade level a student is currently in.
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12047684
Are you declaring grade variable or not before using it?

like:

dim grade as string

or
 dim grade as integer

?
0
 

Author Comment

by:kwh3856
ID: 12047696
I dim the grade as string originally
0
 

Author Comment

by:kwh3856
ID: 12047703
here is the code

 Dim objStreamReader As StreamReader
        Dim strLine As String
        Dim myConnString As String
        Dim admDate As String
        Dim madmDate As DateTime
        Dim grade As String
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12047718
Try adding a trim, in the select case

 Select Case grade.trim
     Case grade = "9"
         .
         .
     Case grade = "10"
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12047769
You don't need to convert the value to numeric

grade = Val(Mid(strLine, 5, 2))

just leave it like

grade = Mid(strLine, 5, 2)
0
 
LVL 8

Accepted Solution

by:
wguerram earned 1000 total points
ID: 12047786
Did you try the trim?

if so and it didn't work try this:

initialize the variable to 9 just before the select case and try it, just to see if you are having other problem.

like:

grade = "9"

 Select Case grade
     Case grade = "9"
         .
         .
     Case grade = "10"
0
 

Author Comment

by:kwh3856
ID: 12047864
That did not work either.  I tried the opposite with no success.  Here is how my code currently sits.

Sub Main()
        Dim objStreamReader As StreamReader
        Dim strLine As String
        Dim myConnString As String
        Dim admDate As String
        Dim madmDate As DateTime
        Dim grade As String
        Dim cvtgrade As Int16


objStreamReader = New StreamReader("C:\fbisd\t178914a.dat")
        strLine = objStreamReader.ReadLine
        Do While Not strLine Is Nothing
            admDate = Mid(strLine, 1, 4)
            admDate = admDate.Substring(0, 2) & "/01/20" & admDate.Substring(2)
            madmDate = admDate
            grade = Mid(strLine, 5, 2)
            cvtgrade = Val(grade)


            cvtgrade = 9

            'Calculate Objective Scores Totals
            MsgBox(cvtgrade)

            Select Case cvtgrade

                Case cvtgrade = 3
                    readingEla3AvailableObj1 = 15
                    readingEla3AvailableObj2 = 7
                    readingEla3AvailableObj3 = 6
                    readingEla3AvailableObj4 = 8
                    readingEla3TotalAvailable = 36
                   .......................etc

                Case cvtgrade = 9 --------------------------------------------Fails test and skips to Case cvtgrade = 10
                    readingEla9AvailableObj1 = 9
                    readingEla9AvailableObj2 = 15
                    readingEla9AvailableObj3 = 18
                    readingEla9TotalAvailable = 42


         EndSelect
0
 

Author Comment

by:kwh3856
ID: 12047975
I got it!!!!!!!!!!

Here was the problem.............do not include the variable...just tell it the value you are looking for

Case 9

                    readingEla9AvailableObj1 = 9
                    readingEla9AvailableObj2 = 15
                    readingEla9AvailableObj3 = 18
                    readingEla9TotalAvailable = 42
0
 

Author Comment

by:kwh3856
ID: 12047990
wguerram

Thanks for your help.  You definately got me going in the right direction..

Thanks
Kenny
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12048061
Oh, yes you are right.

i didn't see the difference

look

 Dim x As String

        x = Val("9 ")

        Select Case x.Trim
            Case "9"
                MsgBox("9")
            Case 10
                MsgBox("10")
        End Select

i was making test and wasn't using the variable in the case.

It's great to know you solve your problem.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

834 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