Forum Discussion

hautzenroeder1's avatar
hautzenroeder1
Occasional Contributor
12 years ago

VB Select Case issue

I am optimizing a lot of my If...Then...Else... statements using Select Case.

TestComplete supports:

Select Case {value}

 Case 1 ....

 Case 2 ...

etc

End Select



Visual Basic allows the option of having:

 Case 1 to 10

 Case 11 to 12

etc



However, in Test Complete, this throws an error.



Any suggestions?

This would save a lot of identical Case 1, Case 2, etc coding.
  • This is not a limitation of TestComplete but is instead a limitation of the VBscript language, which is not the same as Visual Basic.



    In the example you provided where value has a range of 1 to 12, you could do the following:



    If (value <= 12) Then

        Select Case value

            Case 11, 12

                ...do something here...

            Case Else

                ...do something here...

        End Select

    Else

        ...do something else...

    End If
  • This also works:



      For random = 0 to 5

        Select Case TRUE

          Case random >= 1 And random <= 3

            log.message("One")

            log.Message("Two")

            log.Message("Three")

          Case random = 4

            log.Message("Four")

          Case random = 5

            log.Message("Five")

        End Select

      Next

  • TonyMro's avatar
    TonyMro
    Occasional Contributor
    This is not a limitation of TestComplete but is instead a limitation of the VBscript language, which is not the same as Visual Basic.



    In the example you provided where value has a range of 1 to 12, you could do the following:



    If (value <= 12) Then

        Select Case value

            Case 11, 12

                ...do something here...

            Case Else

                ...do something here...

        End Select

    Else

        ...do something else...

    End If