1

Here is the snippet:

C_TEXT($1;$text)
C_POINTER($2)

$text:=$1
$vlElem:=Size of array($2->)
Repeat 
    $vlElem:=$vlElem+1
    INSERT IN ARRAY($2->;$vlElem)
    $vlPos:=Position(Char(Carriage return);$1)
    If ($vlPos>0)
        $2->{$vlElem}:=Substring($1;1;$vlPos-1)
        $1:=Substring($1;$vlPos+1)
    Else 
        $2->{$vlElem}:=$1
    End if 
Until ($1="")

And I tried to to initiate the method with the following snippet:

ARRAY TEXT($vtextarr;0)
C_TEXT($vtext)
$vtext:="lorem" + char(Carriage return) + "ipsum" + char(Carriage return) + "lorem"
finv_split_free_text($vtext; $vtextarr)

It reported "4D was expecting a variable" message. What did I do wrong?

Dylan
  • 37
  • 6

2 Answers2

1

There are two problems: 1) is your use of $1. You can't modify a parameter directly except for pointers and objects. 2) is you don't clear the text var when there is no CR.

The error you get is on the Substring call because you can't change the value of $1. All you need to do is reference $text instead of $1:

C_TEXT($1;$text)
C_POINTER($2)

$text:=$1
$vlElem:=Size of array($2->)

Repeat 
  $vlElem:=$vlElem+1
  INSERT IN ARRAY($2->;$vlElem)
  $vlPos:=Position(Char(Carriage return);$text)
    If ($vlPos>0)
      $2->{$vlElem}:=Substring($text;1;$vlPos-1)
      $text:=Substring($text;$vlPos+1)
    Else 
      $2->{$vlElem}:=$text
      $text:=""  //  otherwise nothing ever clears the var
    End if
  Until ($text="")

Set the parameter to a local variable and then process that variable.

You may also want to check out the TEXT TO ARRAY command.

If you pass an object (defined with C_OBJECT, v15+) as a parameter you can make the sort of modifications you showed to specific keys. Many of us still prefer to assign the parameter to a local var anyway.

kirkBrooks
  • 91
  • 5
  • 1
    This is a couple years late, but with v17, you can now use Collections instead of Arrays. Instead of passing a pointer to an array, you can pass a collection. – Kelderic Apr 15 '20 at 14:34
0

The problem is in the second parameter: if you declare it as pointer, you have tu call the method passing a pointer:

finv_split_free_text($vtext; ->$vtextarr)
Umberto Migliore
  • 317
  • 4
  • 17