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.

String Comparisons in a Switch Statement


Question:

I am trying to use the command askItemList and then use a case statement. What I was attempting to do was if the user selected red run file a.exe and if a user selected yellow run file abc.exe and so on. When I do it this way I get an error box that says case can only accept integers. Can someone help me with this?
List = StrCat("Red",@Tab,"Yellow",@Tab,"Brown",@Tab,"Black")
A = AskItemList("Choose your Favorite Color",list,@tab,@sorted,@Single)

Select A
	case Red
		Message("", a)
		break
	case Yellow
		Message("", a)
		break
EndSelect
Switch never uses string constants. Using Switch @true to tells the switch statement to start checking each conditional case statements each condition. The trick is that each condition equates to an integer, 1 for true and 0 for false. A == "Red" actually is an integer. It is evaluated to @TRUE or @FALSE, which are integer values, 1 or 0 respectively. If you said switch @TRUE, then you get a match at the first case statement that evaluates to @TRUE.
List = StrCat("Red",@Tab,"Yellow",@Tab,"Brown",@Tab,"Black")
A = AskItemList("Choose your Favorite Color",list,@tab,@sorted,@Single)

Select @TRUE
	case A == "Red"
		Message("", a)
		break
	case A == "Yellow"
		Message("", a)
		break
EndSelect 

>I am guessing that by using >the @true you are telling >winbatch to use a string >constant and that takes care >of the integer errror?
Article ID:   W15955
File Created: 2010:06:21:08:40:32
Last Updated: 2010:06:21:08:40:32