czardas Posted January 13, 2010 Share Posted January 13, 2010 (edited) Select Case $var == 0 $msg = "Do something" Case $var == 1 $msg = "Do something else" EndSelectSelect Case $var == 0 $msg = "Do something" Case $var == 1 $msg = "Do something else" Case Else ; Don't do anything. EndSelectEdit: Oops I hit post before I asked a question. Haha.I hadn't even decided on the title. Edited January 13, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 13, 2010 Moderators Share Posted January 13, 2010 czardas,And the question is?I think the two Select structures are functionally identical. In the first snippet if $var is anything other than 0 or 1, it never matches a Case and so nothing happens - just like the second where it is explicit.By the way, the use of the == operator is only to make case-sensitive comparisons between strings. Using it anywhere else is a waste of CPU cycles as it goes through a much more complicated algorithm than a plain =. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
czardas Posted January 13, 2010 Author Share Posted January 13, 2010 (edited) czardas,And the question is?Sorry about the delay, No, the question is:Is the first of the two above examples correct (without the 'Case Else' statement). Would that be considered bad syntax, even though it seems to work fine? The help file examples all include a 'Case Else' statement, which is the reason I ask.And yes, they are meant to be identical statements. Thanks for pointing out that '==' should be '='. I made the post before I had finished editing. The variables I am compairing are actually letters in my original script. Edited January 13, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
trancexx Posted January 13, 2010 Share Posted January 13, 2010 I guess in this case it would be more correct to use Switch... EndSwitch anyway. Switch $var Case 0 $msg = "Do something" Case 1 $msg = "Do something else" EndSwitch ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 13, 2010 Moderators Share Posted January 13, 2010 czardas,Me again.Personally, I only use a Case - ; Do nothing structure if I want to make it absolutely clear that I "do nothing" with certain values. But that is just me.... M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
czardas Posted January 13, 2010 Author Share Posted January 13, 2010 (edited) Thanks for the responses. The actual script I'm writing uses some rather complicated arguments and I'm so used to relying on 'If' statements. I need to break out of the habit. I guess I'll try experimenting with 'Switch' as trancexx has shown.Edit: I was missing the fact that the help file indicates that 'Case Else' is not required. It was the examples that threw me. Edited January 13, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now