Results 1 to 9 of 9

Thread: Easy Javascript question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    Thumbs up

    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

  2. #2
    Member
    Join Date
    Jun 2000
    Location
    Toronto, Canada
    Posts
    52
    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    nah i meant javascript

    but i think i have it sorted out now, so thats cool
    Cheers for the info Mel.
    BW

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    Unhappy Nop i was wrong

    I don't have it sorted. Anyone out there that can help me?
    BW

  5. #5
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    Code:
    <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]
    "People who think they know everything are a great annoyance to those of us who do."

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    Talking Thanks to Noone

    Cheers for that.
    I had almost given up hope.
    BW

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    one last note

    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

    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]

  8. #8
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    There shoudlnt be any reason strings wouldnt work.
    this is a better example, I forgot the break statements in the other one:
    Code:
    <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]
    "People who think they know everything are a great annoyance to those of us who do."

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    Excellent

    With Default and break on my side i now have it going properly. Thanks heaps Noone.
    BW

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width