New Releases: SRP ActiveX Controls 4.1.5 and SRP Utilities 2.1.1
SRP ActiveX Controls 4.1.5 gets minor fixes and SRP Utilities 2.1.1 gets a major new feature.
Unpacking
Unpacking is new feature to the SRP_PreCompiler that lets you assign elements of a dynamic array into variables all on a single line! For example, if you use the SRP_Date Decode service, you’ll get an @FM delimited array of information. If you wanted to pull the year, month, and day, you would traditionally need to do this:
Info = SRP_Date("Decode", SRP_Date("Today", 1))
Year = Info<1>
Month = Info<2>
Day = Info<3>
With unpacking, you can do this in one line:
(Year, Month, Day) = SRP_Date("Decode", SRP_Date("Today", 1))
The unpacking syntax is activated when you surround your variables in parenthesis. Order matters. The first variable gets item <1>, the second gets item <2>, and so on. You can skip a position using the NULL keyword, an underscore, or just omitting. For example, if you wanted year and day, but not the month, any of these three formats will work:
(Year, NULL, Day) = SRP_Date("Decode", SRP_Date("Today", 1))
(Year, _, Day) = SRP_Date("Decode", SRP_Date("Today", 1))
(Year,,Day) = SRP_Date("Decode", SRP_Date("Today", 1))
If you need to unpack an array with a delimiter that is not @FM, then you add the USING keyword after the parenthesis:
(First, _, Last) using ',' = "John,Seymour,Doe"
This syntax is useful for smaller arrays when readability is important to you. This is not useful for parsing large records. You can only unpack into individual variables, not into other arrays or matrices.
SRP_JSON
SRP_Json gets two new services, AddValueArray and SetValueArray. These services allow you pass a dynamic array of values directly into a JSON element so you don’t have to manually loop through the array to add each value. It turns code like this:
ValueArray = "1,2,3,4"
If SRP_Json(ArrayHandle, "New", "Array") then
For each Value in ValueArray using ","
SRP_Json(ArrayHandle, "AddValue", Value)
Next Value
SRP_Json(ObjectHandle, "Set", "my-array", ArrayHandle)
SRP_Json(ArrayHandle, "Release")
end
Into code like this:
SRP_Json(ObjectHandle, "SetValueArray", "my-array", "1,2,3,4", ",")
Other Tweaks
There are other fixes and minor improvements. See the version histories for SRP ActiveX Controls and SRP Utilities for complete information.
Leave a Reply