简体   繁体   中英

Null value of String Array in Function of Crystal Reports - Crystal Syntax

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?

What I've tried

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.

My code

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM