I have a weblist that causes a page on my site to behave different ways depending on the name of the country selected. I want to find the most efficient way to have QTP execute the desired behavior depending on the country variable. Rather than have 50 if...then statements, would some of the gurus here tell me what the best way to go about this?
I've never created a function before, and I'm not sure if that's the way I should go. I thought about an array, but I can't figure out how to get the code to check the entire list to see if the variable is being called or not.
For a start a select case statement would be more efficient within a function. You could have several subs each relating to different relation ships and then call the subs in the select case statement like this
<select english from list>
<Code relating to english language variant here>
<select french from list>
<Code relating to french language variant here>
Select Case language_type
You would then call it like this
This is a better way of handling many conditions, not sure if its the best but it works for me.
The case statement is really only more for organization and readability.. you could do the same thing with nesting... I'd offer more help.. but it's time for me to go home.. i'll check back on this later and post a better respones
Whilst we are waiting for SimJones better response using nesting, I would just like to correct their comment above
A case statement actually simplifies over complex nested actions. Select Case statements handle multiple-choice conditions better than If...then...Else.The Select Case statement is useful when you must make several choices based on data values. A select case executes faster than nested If...then...Else. Its is not just there to aid readability. Another thing, a select case is much more easier to maintain and change than complex nested statements.