I am trying to create a Function that parses a string of this structure:
4:20,5:30,8:40
It contains 15 values separated by commas at max, but it can also contain less than 15 values.
I use the Split method to split these values first, and create an array with those split values. Then I have a for loop in which I split the values again, this time using ":" as the separator.
But before using that second split, I want to check wether the string is null or not. How can I do that? What does Split do if the array variable in which I assign it to is larger than the values it will return? Does it fill it with blank strings, null values?
I tried checking an empty string (""), blank space (" ") and using IsNull. The first two options do not work (the function returns nothing, as if it was always false) and the last one gives me an error as if I can't use that method to check that string variable.
Function (StringVar Detalle)
local NumberVar DetalleSplitLength;
local NumberVar i := 1;
local StringVar TipoMoneda;
local StringVar Result;
local StringVar array DetalleSplit;
local StringVar array TipoMonedaSplit;
local BooleanVar First := True;
If Detalle <> "" Then
(
DetalleSplit := Split(Detalle, ',');
DetalleSplitLength := 15;
Redim Preserve DetalleSplit [DetalleSplitLength];
for i := 1 to DetalleSplitLength do
(
' This is the conditional that fails to do what I need.
If (DetalleSplit[i] <> "") Then
(
TipoMonedaSplit := Split(DetalleSplit[i], ':');
If TipoMonedaSplit[2] <> "0" And Result <> "" Then
(
' Here I parse the result.
);
);
)
);
Result
I am using Crystal Syntax. I added the comments with "'" so that they were formatted with colors correctly.
It was my mistake in the inner conditional as @mweber pointed out. The comparation with the empty string is correct.
Here is the working code:
(I will edit it later and add it)
I suppose your test for non-empty values does work correctly, but the condition just before the inner block is not correct:
If TipoMonedaSplit[2] <> "0" And Result <> "" Then
(
' Here I parse the result.
);
The part And Result <> "" prevents your function from ever entering the block where you want to parse the result, as Result
is not initialized before.