My two previous examples didn’t include any error catching code in them mostly because without an example of your current code I don’t fully know what potential errors may occur.
total number of components in _elements is not 4
At a minimum the 2nd of my examples should check that there are enough “elements” to assign a value to each of your four variables…
(if: _elements's length >= 4)[
(set: $a to _elements's 1st)
(set: $b to (num: _elements's 2nd))
(set: $c to (num: _elements's 3rd))
(set: $d to (num: _elements's 4th))
]
…however there are any number of things that may go wrong when processing an end-user entered value, some of them being:
1: Did they enter a value at all?
(if: $m is "")[What to do when no value was supplied?]
2: Did they add additional white SPACE characters to the start and/or end of the value entered?
eg. " Mike-03-00-25 ")
(set: $m to (trimmed: $m))
see: (trimmed:)
2b: Did they add additional white SPACE characters within the entered formatted String value itself?
eg. "Mike -03-00- 25")
(set: $a to (trimmed: _elements's 1st))
(set: $b to (num: (trimmed: _elements's 2nd)))
(set: $c to (num: (trimmed: _elements's 3rd)))
(set: $d to (num: (trimmed: _elements's 4th)))
3: Did they enter the “name” element of the formatted String in a letter-casing different to what you want?.
eg. "mike-03-00-25"
or "MIKE-03-00-25"
or "mIKe-03-00-25"
(set: $a to (upperfirst: _elements's 1st))
see: (upperfirst: )
4: Did they enter a “name” element longer that what you want?
eg. "Mike the great, who travels this wide land righting wrongs-03-00-25"
(this issues is a lot harder to solve using only the default macros, you will likely need to create one or more Custom Macros)
enters a non-numeric value in ##s
This issue is also hard to solve using just the default macros, because none of them handle the “Is A Numerical Character” or “Contains Non-numerical Character(s)” situations for the String data-type. So again you would likely need to implement one or more Custom Macros.
The following is one potential implementation. The code would need to be placed within your project’s startup tagged Passage.
(set: $isNumerical to (macro: str-type _value, [
(set: _numerical to true)
(if: _value's length is 0)[
(set: _numerical to false)
]
(else:)[
(set: _valid to (a: '0','1','2','3','4','5','6','7','8','9','.','-'))
(for: each _char, ..._value)[
(if: _numerical)[
(if: _valid does not contain _char)[
(set: _numerical to false)
]
]
]
]
(output-data: _numerical)
]))
The usage of the above ($isNumerical:) custom macro would likely look something like…
(set: _value to (trimmed: _elements's 2nd))
(if: ($isNumerical: _value))[
(set: $b to (num: _value))
]
(else:)[
(set: $b to 0)
]
note: It may be possible to use some combination of the String data-type’s operators (like some of) to achieve a similar “is numerical” outcome, but I gave up after trying a couple of combinations.