Jump to content

Simple Syntax Question


czardas
 Share

Recommended Posts

Select
    Case $var == 0
        $msg = "Do something"
    Case $var == 1
        $msg = "Do something else"
EndSelect

Select
    Case $var == 0
        $msg = "Do something"
    Case $var == 1
        $msg = "Do something else"
    Case Else
    ; Don't do anything.
EndSelect

Edit: Oops I hit post before I asked a question. Haha.

I hadn't even decided on the title.

Edited by czardas
Link to comment
Share on other sites

  • Moderators

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 =. :D

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

czardas,

And the question is?

Sorry about the delay, :D 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 by czardas
Link to comment
Share on other sites

  • Moderators

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.... :D

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

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 by czardas
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...