Micro Focus QTP (UFT) Forums
Using Range in Select Case Statement - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Using Range in Select Case Statement (/Thread-Using-Range-in-Select-Case-Statement)



Using Range in Select Case Statement - Studymode - 12-14-2017

Hi all, 


So I am very new to qtp and I was wondering if anyone could provide some input. So I am a little bit confused about the select case statement. Here is my statement below.

 Age = inputbox("enter age")

Select Case Age
    Case > 5
    msgbox "young"
    Case 6 to 15
    msgbox "still young"
    Case 16 , 21
    msgbox "still young"
    Case 22 , 30
    msgbox "get your own spot"
    Case 31 , 100
    msgbox "settled"
End Select

My question is how do I use range, in this case, I have tried a lot of different ways but nothing seems to work.
but I did manage to get this to work, but there has to be a simpler way. 

Select Case Age

    Case 1,2,3,4,5
    msgbox "too oung"
    Case 6,7,8,9,10,11,12,13,14,15
    msgbox "still young"
    Case 16,17,18,19,20, 21
    msgbox "growing up"
End Select

I want to know if there is an easier way to write this, instead of writing all of the integers. I want the first case value to be 1 through 5 if that's possible and so on and so forth. Any help or tips would be greatly appreciated. Thanks in advance.