简体   繁体   English

Crystal Reports 的 Function 中字符串数组的 Null 值 - Crystal 语法

[英]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:我正在尝试创建一个解析此结构的字符串的 Function:

4:20,5:30,8:40

It contains 15 values separated by commas at max, but it can also contain less than 15 values.它最多包含 15 个以逗号分隔的值,但也可以包含少于 15 个的值。

I use the Split method to split these values first, and create an array with those split values.我首先使用 Split 方法拆分这些值,然后使用这些拆分值创建一个数组。 Then I have a for loop in which I split the values again, this time using ":" as the separator.然后我有一个 for 循环,在其中我再次拆分值,这次使用“:”作为分隔符。

But before using that second split, I want to check wether the string is null or not.但在使用第二次拆分之前,我想检查字符串是否为 null。 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?如果我分配给它的数组变量大于它将返回的值,Split 会做什么? Does it fill it with blank strings, null values?它是否用空白字符串 null 值填充它?

What I've tried我试过的

I tried checking an empty string (""), blank space (" ") and using IsNull.我尝试检查空字符串(“”)、空格(“”)并使用 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 什么也不返回,好像它总是错误的一样),最后一个给我一个错误,好像我不能使用该方法检查该字符串变量。

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.我用“'”添加了注释,以便它们正确格式化为 colors。

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.部分And Result <> ""阻止您的 function 进入您要解析结果的块,因为Result之前没有初始化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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