PDA

Click to See Complete Forum and Search --> : Easy Javascript question


But_Why
Aug 6th, 2000, 09:26 PM
This ones probably so easy that you'll all cringe and think that i'm stupid. But being a learner of Javascript, it has to be asked.
In VB there is the Select Case statement, and i think in C there is the Switch statement, which is a whole lot quicker than a heap of if then else statements.
Now on to my question, is there anything similar in VB?
Or do i have to resort to a whole lot of if/then statements. And with what i have in mind its gonna be a WHOLE lot of if then statements.
Cheers people.
BW :cool:

run2thesun
Aug 6th, 2000, 10:48 PM
If you mean VBScript then it has the same syntax as ol'
VB - Select Case. I'm not an expert on VBScript and I
haven't done anything in it but i'm pretty sure that
that' the way it is.

Mel.

But_Why
Aug 6th, 2000, 10:51 PM
but i think i have it sorted out now, so thats cool
Cheers for the info Mel.
BW :cool:

But_Why
Aug 8th, 2000, 06:40 PM
I don't have it sorted. Anyone out there that can help me?
BW :cool:

noone
Aug 8th, 2000, 06:51 PM
<Script Language = "JavaScript">
var x = 7;

switch(x) {
case 1:
alert("nope");
case 3:
alert("still not it");
case 7:
alert("thats the one");
}
</Script>


[Edited by noone on 08-08-2000 at 11:51 PM]

But_Why
Aug 8th, 2000, 06:56 PM
Cheers for that.
I had almost given up hope.
BW :cool:

But_Why
Aug 8th, 2000, 07:10 PM
is there an else part for switch?

eg
switch(x)
{
case 1:
...
case 2:
...
case else:
...
}
to catch it if its not one of the previous options?
BW :cool:

PS also does it work for strings not only numbers? I have one working with a string and it seems to go through all the options.

[Edited by But_Why on 08-08-2000 at 08:15 PM]

noone
Aug 8th, 2000, 07:27 PM
There shoudlnt be any reason strings wouldnt work.
this is a better example, I forgot the break statements in the other one:

<Script Language = "JavaScript">
var x = 7;

switch(x) {
case 1:
alert("nope");
break;
case 3:
alert("still not it");
break;
case 9:
alert("thats the one");
break;
default:
alert("none of them");
}
</Script>


[Edited by noone on 08-08-2000 at 11:52 PM]

But_Why
Aug 8th, 2000, 07:33 PM
With Default and break on my side i now have it going properly. Thanks heaps Noone.
BW :cool: