Results 1 to 10 of 10

Thread: Help with Select Case Statement

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Help with Select Case Statement

    Ok, I have used this one in a while. I usually just use IF...THEN statements. How should I set this up?

    VB Code:
    1. Select Case
    2. Case 1   ' Option button 1 is selected on my form
    3.               'do stuff here
    4.  
    5. Case 2  ' Option button 2 is selected
    6.  
    7. etc.
    8.  
    9.  
    10. Enc Select

    I got an erro after I typed "Select Case" and hit enter. Something like expected expression. what am I leaving out?

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Talking Man I screwed up that post...

    I can't type today!!!!!!!!!!

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    -= a peet post =-

  4. #4
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    VB Code:
    1. Select Case [i]Expression[/i]
    2.     Case 1
    3.         'Do Something
    4.     Case ...
    5.         '...
    6.     Case Else
    7.         '...
    8. End Select


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Help with Select Case Statement

    Originally posted by hipopony66
    Ok, I have used this one in a while. I usually just use IF...THEN statements. How should I set this up?

    VB Code:
    1. Select Case
    2. Case 1   ' Option button 1 is selected on my form
    3.               'do stuff here
    4.  
    5. Case 2  ' Option button 2 is selected
    6.  
    7. etc.
    8.  
    9.  
    10. Enc Select

    I got an erro after I typed "Select Case" and hit enter. Something like expected expression. what am I leaving out?
    hopefuly you didnt spell it "Enc Select" in your code

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    No, I didn't

    I spelled END SELECT. Do I not need select case for this purpose? I need to do something different depending on which one of 6 option buttons are selected.

  7. #7
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    The If...ElseIf...ElseIf...ElseIf...ElseIf...Else loop is better in this case. Because the optionbuttons' values are stored in different variables, you should NOT use a Select statement but a nested if.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    I disagree with Microbasic because he is overlooking the very useful but under-used Select Case True.
    In this case it would be used something like this
    VB Code:
    1. Select Case True
    2.     Case Opt1.Value = True
    3.  
    4.     Case Opt2.Value = True
    5.  
    6. etc.
    7.  
    8.  
    9. End Select

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Talking Well, how bout this to ponder on!

    Thanks Martin, I think that's what I need. How bout this though? I've heard good a bad things about this. What if I created a control array with 6 option buttons called optWhatToDo, and then use a Select case statement with the index values of the control? Can anyone say anything good or bad about control arrays?? The VB class I took last semester used them a lot, but I never used them before the class and rarely do now.

  10. #10
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    control arrays save memory if you are using labels to have a static usage(they won't change). they can sometimes be very useful and can save you changing many subs of the same controls with almost the same code.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

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