WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Use Switch with Variable Strings

Keywords:    select switch cases

Question:

I would like to use "Switch" using strings, for example: switch name: case "G. C.":
.....
break
case "My Name":
.....
break
endswitch
I got error message on this block, because switch can use only integer variable. Is there is any way to do "case" on strings?

Answer:

Here's a handy trick:
switch @true
case var == "Paul"
break
case var == "Alice"
break
endSwitch
Or you could also do (less elegant)---convert it to an integer:
var="fred"

list="paul fred sam alice"
paul=1
fred=2

xx=ItemLocate(var,list," ")

switch xx
case paul
break
case fred
break
case 3 ; sam
break
case 4 ; alice

Article ID:   W13195
Filename:   Switch with a Variable Name.txt
File Created: 2003:07:08:11:49:08
Last Updated: 2003:07:08:11:49:08