Page History
...
- For Each Loops
- Conditional Return Statement
- Service Modules
- Event Modules
- Unit Test Modules
- Unpacking (Added in 2.1.1)
- Super Strings (Added in 2.2.11)
Extended BASIC+ Syntax
For Each Loops
...
NOTE: You can only unpack into individual variables, not into other arrays or matrices.
Super Strings
IMPORTANT: Super strings were added in 2.2.11 and are not supported in prior versions.
Super strings offer some powerful string manipulation options. Super strings use accent marks, which means you can use single and double quotations in your string without concatentation:
| Code Block |
|---|
Var = `"I'd be delighted," she said cheerfully.` |
Super strings also support interpolation. Interpolating a variable is more compact form of concatenation: it's like weaving your variables into the string. If, for example, you need to use variables or system variables in a string, you can do this:
| Code Block |
|---|
Var = `Hello, $Name. Your login is @USERNAME.` |
In super strings, the $ and @ characters are reserved. The dollar sign means you are weaving in a variable or expression. In the above example, there is a variable call Name, and the value of that variable will be concatenated into the string at runtime. The at-symbol means you are weaving in a system variable. If you need these characters in your super string, just double them up, e.g., `$$5.00`.
Expressions are supported. To use them, you need use curly braces after the dollar sign, like so:
| Code Block |
|---|
Var = `Today is ${SRP_Date("DayOfWeekName", SRP_DateTime("DayOfWeek", DateTime))}, it's ${SRP_DateTime("Format", DateTime, "HH:mmaa")} now.` |
Important: Using angle brackets on a variable is an expression, so you must use curly braces:
| Code Block |
|---|
Incorrect = `The book "$BookInfo<1>" was written by $BookInfo<2>.`
Correct = `The book "${BookInfo<1>}" was written by ${BookInfo<2>}.` |
Supers strings are optimized to produce the fewest concatenations possible. For example, when you interpolate delimiters into your strings, concatenation is avoided:
| Code Block |
|---|
// 8 concatenations
OldWay = "Monday":@FM:"Tuesday":@FM:"Wednesday":@FM:"Thursday":@FM:"Friday"
// No concatenations
NewWay = `Monday@FMTuesday@FMWednesday@FMThursday@FMFriday` |
In the SRP Editor, interpolated variables are syntax highlight inside the strings to make readability much easier. But we're not done! Super strings also allow you to work with raw, multilined strings:
| Code Block |
|---|
Var = ```
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
</breakfast_menu>
``` |
The above super string will compile into a single string, with line breaks and indentations. There are a couple rules to follow for the precompiler to properly understand your super string:
- Opener and closer must be at least 3 accent marks, and they must match. If you open with five accents, you must close with 5 accents.
- Opener and closer must be on their own lines. The string begins on the line after your opener and ends on the line just before your closer.
- Blank lines and line breaks are included in the string.
- Any whitespace that appears in front of your closer is ignore on all other lines. In the above example, there is one tab in front of the closer, so one tab will be ignore at the beginning of each line.
- You can comment out lines, but you must use the asterisk and it must be the first character of the line. (Using Ctrl+/ in the SRP Editor does this for you).
This can be useful for storing large amounts of data that you don't want stored in a record for someone to mess with. For example, the setup XML for the SRP Ribbon Control. The precompiler will account for string size limits and perform concatenation as needed. In the debugger, the whole string will behave like a single operation. Note, however, that object code in OpenInsight does have a size limit for literal data. In almost all circumstances, you don't have to worry about it, but if you include pages and pages of strings in a stored procedure that is very large, you could run into issues.
Multilined super strings also support interpolation, great for setting up some JSON:
| Code Block |
|---|
Var = ```
{
"name" : "$Name",
"day-of-week" : "${SRP_Date("DayOfWeekName", SRP_DateTime("DayOfWeek", DateTime))}",
"time" : "${SRP_DateTime("Format", DateTime, "HH:mmaa")}"
}
``` |
Lastly, you might want to see your string nicely formatted in your code, but you don't want all that whitespace at runtime. In that case, you can use the "-compress" argument:
| Code Block |
|---|
New = ``` -compress
{
"CloseButtons" : true,
"Tabs" : [
{
"TabCaption" : "${Title<1>}",
"TabImage" : "${Icon<1>}"
},
{
"TabCaption" : "${Title<2>}",
"TabImage" : "${Icon<2>}"
}
]
}
``` |
The -compress argument will trim each line and strip all line breaks at compile time. In the above example, that's okay, because JSON doesn't need all that whitespace anyway.
Caveats
The SRP PreCompiler will work in any BASIC+ editor, but there is an important caveat to using Enhanced BASIC+ in anything other than the SRP Editor. The SRP Editor recognizes the new syntax and highlights code accordingly whereas the builtin OI Editor will not. Everything will still compile and run, but it will a little harder to read. Moreover, some features of the PreCompiler, such as the metadata, won't impede your code, but you also won't get the most out of your development outside of the SRP Editor.
...