[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Case statement fails case when it is not supposed to

Posted on 2004-09-13
15
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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