Is there a way to convert the following into a Select Case statement?

If ((x = 1) And (y = 1)) Then
z = 123
ElseIf ((x = 1) And (y = 2)) Then
z = 456
ElseIf ((x = 2) And (y = 1)) Then
z = 789
End If

Re: Multiple If's by mr_unreliable

mr_unreliable
Thu Dec 01 08:57:28 CST 2005

hi Andy,

Yes, there is a way, using the "Select Case True" approach.

See this:

http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_thread/thread/95f115f2e64dcf5e/d73d8dea01cacef8?lnk=st&q=%22select+case+true%22+group%3Amicrosoft.public.scripting.vbscript&rnum=6&hl=en#d73d8dea01cacef8

Applying that to your situation (air code):

--- <snip> ---
select case True
case ((x = 1) And (y = 1))
z = 123
case ((x = 1) And (y = 2))
z = 456
case ((x = 2) And (y = 1))
z = 789

case else
MsgBox("uh-oh. My select stmt failed!!!")
end select
--- </snip> ---

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)


AndyZa wrote:
> Is there a way to convert the following into a Select Case statement?
>
> If ((x = 1) And (y = 1)) Then
> z = 123
> ElseIf ((x = 1) And (y = 2)) Then
> z = 456
> ElseIf ((x = 2) And (y = 1)) Then
> z = 789
> End If
>

Re: Multiple If's by AndyZa

AndyZa
Thu Dec 01 13:52:29 CST 2005


mr_unreliable wrote:

> Yes, there is a way, using the "Select Case True" approach.
<snip>
I knew it!!!

> Applying that to your situation (air code):
> select case True
> case ((x = 1) And (y = 1))

Aaah! I was doing this:

case (x = 1) And (y = 1)
note the missing brackets...

Thanks


Re: Multiple If's by Dr

Dr
Sun Dec 04 14:51:33 CST 2005

JRS: In article <1133445931.966839.283400@g43g2000cwa.googlegroups.com>
, dated Thu, 1 Dec 2005 06:05:32 local, seen in news:microsoft.public.sc
ripting.vbscript, AndyZa <andyza@webmail.co.za> posted :
>Is there a way to convert the following into a Select Case statement?
>
>If ((x = 1) And (y = 1)) Then
> z = 123
>ElseIf ((x = 1) And (y = 2)) Then
> z = 456
>ElseIf ((x = 2) And (y = 1)) Then
> z = 789
>End If

Maybe something like

select case x*10 + y
case 11
z = 123
case 12
z = 456
case 21
z = 789
case else
z = 0

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

Re: Multiple If's by de

de
Tue Dec 06 14:46:01 CST 2005

Which would give possibly incorrect results because x=1,y=1 gives the same
case as x=0.y=11

"Dr John Stockton" <jrs@merlyn.demon.co.uk> wrote in message
news:YcL6rMDVb1kDFwk$@merlyn.demon.co.uk...
> JRS: In article <1133445931.966839.283400@g43g2000cwa.googlegroups.com>
> , dated Thu, 1 Dec 2005 06:05:32 local, seen in news:microsoft.public.sc
> ripting.vbscript, AndyZa <andyza@webmail.co.za> posted :
>>Is there a way to convert the following into a Select Case statement?
>>
>>If ((x = 1) And (y = 1)) Then
>> z = 123
>>ElseIf ((x = 1) And (y = 2)) Then
>> z = 456
>>ElseIf ((x = 2) And (y = 1)) Then
>> z = 789
>>End If
>
> Maybe something like
>
> select case x*10 + y
> case 11
> z = 123
> case 12
> z = 456
> case 21
> z = 789
> case else
> z = 0
>
> --
> © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00
> MIME. ©
> Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms &
> links;
> Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm,
> etc.
> No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail
> News.



Re: Multiple If's by Dr

Dr
Wed Dec 07 07:08:37 CST 2005

JRS: In article <#4jLUYq#FHA.3568@TK2MSFTNGP09.phx.gbl>, dated Tue, 6
Dec 2005 14:46:01 local, seen in news:microsoft.public.scripting.vbscrip
t, de Graff <rjdegraff@hydro.mb.ca> posted :
>Which would give possibly incorrect results because x=1,y=1 gives the same
>case as x=0.y=11

Accommodated by "something like"; the multiplier must obviously be
chosen to be greater than the range of variable y.

Please do not top-post or over-quote, especially signatures.

>"Dr John Stockton" <jrs@merlyn.demon.co.uk> wrote in message
>news:YcL6rMDVb1kDFwk$@merlyn.demon.co.uk...
>> JRS: In article <1133445931.966839.283400@g43g2000cwa.googlegroups.com>
>> , dated Thu, 1 Dec 2005 06:05:32 local, seen in news:microsoft.public.sc
>> ripting.vbscript, AndyZa <andyza@webmail.co.za> posted :
>>>Is there a way to convert the following into a Select Case statement?
>>>
>>>If ((x = 1) And (y = 1)) Then
>>> z = 123
>>>ElseIf ((x = 1) And (y = 2)) Then
>>> z = 456
>>>ElseIf ((x = 2) And (y = 1)) Then
>>> z = 789
>>>End If
>>
>> Maybe something like
>>
>> select case x*10 + y
>> case 11
>> z = 123
>> case 12
>> z = 456
>> case 21
>> z = 789
>> case else
>> z = 0
>>
>> --
>> ©



--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.