Jump to content

Select Case / Selecting multiple cases?


Recommended Posts

Background - I have a Select Case statement with 18 possible cases. I want to close my GUI when one of those cases occurs, but for ALL other cases, I want to leave the GUI alone.

The way I did it originally was to add a line to close the GUI in each of those 18 cases, but that means adding 18 more lines of code to do one function.

Is there a way to say (for example) "If case = case 1 through case 18, then closeGUI()"? Or a better way to do this?

Pseudo code of my current script-

While1

Select

Case 1 $msg=ms1

closeGUI()

Case 2 $msg=ms2

closeGUI()

Case 3 $msg=ms3

closeGUI()

Case 4 $msg=ms4

closeGUI()

EndSelect

Wend

For this particular script, the speed increase would be noticeable, but it makes my code look messy to have 18 extra lines of code, and I want to try to get my future scripts cleaner/faster.

Thanks all,

-DWad

Link to comment
Share on other sites

Background - I have a Select Case statement with 18 possible cases. I want to close my GUI when one of those cases occurs, but for ALL other cases, I want to leave the GUI alone.

The way I did it originally was to add a line to close the GUI in each of those 18 cases, but that means adding 18 more lines of code to do one function.

Is there a way to say (for example) "If case = case 1 through case 18, then closeGUI()"? Or a better way to do this?

Pseudo code of my current script-

While1

Select

Case 1 $msg=ms1

closeGUI()

Case 2 $msg=ms2

closeGUI()

Case 3 $msg=ms3

closeGUI()

Case 4 $msg=ms4

closeGUI()

EndSelect

Wend

For this particular script, the speed increase would be noticeable, but it makes my code look messy to have 18 extra lines of code, and I want to try to get my future scripts cleaner/faster.

Thanks all,

-DWad

This would cut down on lines, but it'd be a long line:

Select
Case $msg=ms1 or $msg=ms2 or $msg=ms3;...
CloseGUI()
EndSelect

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

Switch Random(1, 5, 1)
    Case 1
        ConsoleWrite('Lorem ')
        ContinueCase
    Case 2
        ConsoleWrite('ipsum ')
        ContinueCase
    Case 3
        ConsoleWrite('dolor ')
        ContinueCase
    Case 4
        ConsoleWrite('sit ')
        ContinueCase
    Case Else
        ConsoleWrite('amet' & @LF)
EndSwitch

Link to comment
Share on other sites

  • Moderators

Authenticity,

Love the quote! ;-)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Zisly got me slightly closer.

I ended up using a variable that would close the GUI after the Switch statements unless it got to the case else (which would set the variable to keep the GUI open).

Is there no way to say something along the lines of "If case 1,2,3 or 4, do this, else do that"?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...