Search | User Listing Vidsite | Calendars | Quotes
Home Page ->  OLang, OScript & OPilot -> OScript & OLang Syntax & Methods -> View ThreadLogon (or Register, or Join TradeTight)

You are logged in as a limited-access Guest.To join TradeTight, first read the info in the Organization & Content room, then click the link above. 

1 Timothy 6:6-8 (ESV) … Now there is great gain in godliness with contentment,  for we brought nothing into the world, and we cannot take anything out of the world.  But if we have food and clothing, with these we will be content.


Select Case syntax
Jump to page : 1
Now viewing page 1 [50 msgs/pg]
Jump to room :
JimDean
Posted 3/28/2015 9:04 AM (#6195)
Subject: Select Case syntax



Owner/Admin

Posts: 3925
2000100050010010010010025
Location:
USA: GA, Lawrenceville
Select Case is very useful, but most folks don't realize how flexibly it can be set up. It's not only easier to type and read than a series of if/elseif.../endif clauses, but it also allows for very "compact" conditional combinations, by using commas and "to" ranges.

Here is an example (snapshot, so indents aren't lost) showing lots of variations ... it's an OLang'd & enhanced form of the one given here: https://msdn.microsoft.com/en-us/library/cy37t14y.aspx

Notes:
1. Case statements do NOT have to be in sequential order
2. "To" ranges need to be from min to max (ie increasing).
3. The "To" ranges are continuous, not limited to integer values
4. No "step" parameter is allowed or needed for the To ranges
5. Case Else covers all situations not within the prior ones - put it LAST
6. If ranges overlap, the first Case found is the one that applies
7. The initial IndexValue can be anything that resolves to things the Case's test for
8. Index and cases can be numbers or strings (or dates or booleans, etc)
9. Unlike "To" ranges, comma-lists do not need to be from min to max

Application suggestions:
1. always use orderly indentation to preserve readability
2. be sure that you have all the possible Index values covered
3. sometimes it saves calc time to skip over the select case by wrapping it in an if clause


(SelectCase Example.png)



Attachments
Attachments SelectCase Example.png (13KB - 4 downloads)
Top of the page Bottom of the page
DonSchuman
Posted 3/14/2020 8:18 PM (#9802 - in reply to #6195)
Subject: Select Case syntax



Veteran

Posts: 212
100100
Location:
USA: TX, Mansfield
I want to use "Select Case" in some code I am trying to write.

Below is a hybrid of Select Case and If, Then, Else

Can this be done with Select Case or do I have to use If statements?

Select Case StateOfVariable
If EMA1 > EMA2 And Low[1] > EMA1 And Low <= EMA1 And Low >= EMA2 Then
StateOfVariable = Long
Else If EMA2 > EMA1 And High[1] < EMA1 And High >= EMA1 And High <= EMA2 Then
StateOfVariable = Short
Else
StateOfVariable = Flat
End If

If low <= EMA2 Then StateOfVariable = Flat Else StateOfVariable = Long

If high >= EMA2 then StateOfVariable = Flat Else StateOfVariable = Short
Top of the page Bottom of the page
JimDean
Posted 3/14/2020 8:46 PM (#9803 - in reply to #9802)
Subject: Select Case syntax



Owner/Admin

Posts: 3925
2000100050010010010010025
Location:
USA: GA, Lawrenceville
The code you showed is incorrect syntax as-is. Comment out the select case statement.

What you are trying to accomplish is more suitable for if/then/elseif/else/end if, since the conditions are formulae rather than alternative values of a variable.

Also note that “elseif” is a single word. The parser might accept it as two, but potentially it might create issues. Best to be safe. “End if” is two words.
Top of the page Bottom of the page
DonSchuman
Posted 3/14/2020 9:25 PM (#9804 - in reply to #6195)
Subject: Select Case syntax



Veteran

Posts: 212
100100
Location:
USA: TX, Mansfield
' 5=Long; 3=Flat; 1=Short

If EMA1 > EMA2 And Low[1] > EMA1 And Low <= EMA1 And Low >= EMA2 Then
varState = Long
ElseIf EMA2 > EMA1 And High[1] < EMA1 And High >= EMA1 And High <= EMA2 Then
varState = Short
Else
varState = Flat
End If



If Low <= EMA2 Then
varState = Flat
Else
varState = Long
End If

If High >= EMA2 Then
varState = Flat
Else
varState = Short
End IF
Top of the page Bottom of the page
Jump to page : 1
Now viewing page 1 [50 msgs/pg]
( E-mail a Link | Printer Version | Search Room )

Owner of site: Jim Dean -- Forum content is confidential, and may not be distributed without written permission.