views:

198

answers:

1

Id expect this to work (below) If iTestVar is 1, I'd expect DoStuff() to be fired. However it always falls into the else.

I have researched const in the past and found they can only be defined outside of classes. The select statement is inside the class.

        'This is defined outside of the class (vbscript won't allow const inside classes)
        Const STOPHERECONSTANT = 1


        Select Case iTestVar
            Case STOPHERECONSTANT

                DoStuff()

            Case Else

        End Select
+2  A: 

My bad, i'm sure I tested this, but I must of missed it, while fixing something else.

I needed to convert the iTestVar:

'This is defined outside of the class (vbscript won't allow const inside classes)
    Const STOPHERECONSTANT = 1


    Select Case CInt(iTestVar)
        Case STOPHERECONSTANT

            DoStuff()

        Case Else

    End Select
Alex Key
You don't cast in VBScript you convert. My guess is iTestVar was assigned a string. If iTestVar is supposed to be a string then you should rename it to sTestVar, alternatively if iTestVar is supposed to be an integer then you should be ensuring that its always assigned an integer at source. You shouldn't have to be constantly converting something that appears to be an integer __to__ an integer.
AnthonyWJones
Thanks for correcting me on the cast vs. convert.Thats the strange thing iTestVar IS always an integar. However when using a const, the only way I seem to get the swtich to work is converting it first.
Alex Key
Pants! My bad once again! I see where the issue lies now, in my scenario iTestVar is being set by a form post. Even though the form post is always posting back a number, the value (i'm guessing) is being passed as a string. Double "my bad" - as I hadn't included it in the original post.
Alex Key