Testing Turbo Integrator Code

In the last post we talked about how we can output String and Numeric values in a Fixed Width Field Format. I realised just after writing the article that I used a not-well-known trick in order to perfect the snippets I posted. This is: Using Calculated Variables to Test Field Calculations.

I’m going to use the example of the numeric field from the last post to present how to better critique your code.

Format: Sign Indicator (1 Character) followed by 26 numeric Characters. 3 Decimal Places are implied.

Before: $150.00
After: +00000000000000000000150000

Before: $-2500.15
After: -00000000000000000002500150

Lets get Started!

Begin with a blank Turbo Integrator Process – This doesn’t need to be saved.

Empty Turbo Integrator Code with Single Variable

Within this new Process open the variables tab. What we are going to do first is setup a calculated variable which is the value we will be formatting. So click the “New Variable” button and name this “value”, when you do so this will open the formula editor. Using standard TI code set the value to our test value from the last post “-2500.15”.

value = -2500.15;

Now that this is done, set the “Contents” field to “Other”.

Add a new string variable called “sResult”. Within the formula window you can now prototype the complex calculation required for the needed format. For each iteration you can click the “Evaluate” Button to test the updated snippet of code.

Calculated Variable Formula Window

The final logic for this formatting (from the last post) is:

From a Numeric Variable:

sResult = IF(value>=0,'+','-') |  FILL('0',26-LONG(  Numbertostring( INT(value * 1000)))) | Numbertostring( INT(value * 1000))

I have to thank David Payten for this one. He first mentioned this as a quick way to debug non-syntactical scripting errors.



You might also like