Textize

The String function turns numbers into text. Textize, turns anything passed to it to text. Well, except BLOBs & Pictures. It'll even convert a 1D array to text (Not 2D arrays though, sorry.)

Basically, it's just a Case Of statement that checks for the type of the field or variable passed and takes appropriate actions. For arrays passed, it returns a single string of the text version of each element of the arrays separated by the specified delimiter.

Here's some examples of how and what:

If vRateOfDecay is 5.
$Text:=Textize (->vRateOfDecay)
$Text = "5"

If aLaser is an array of reals.
$Text:=Textize (->aLaser;False;",")
$Text = "1,7.23,42.24,..."

Okay, so what, String does that, right? Where this becomes useful is when you don't know what type of data the pointer will be pointing to. For instance, if you want to populate a grid of variables on a form from different fields or maybe you want a choice list which only takes string or text arrays or you want your own generic export routine.

  ` Textize
  ` Returns the text equivalent of what was passed

  ` $1 - Pointer to the variable to be Textized
  ` $2 - True if to be returned with "quotes" of the proper type (ie ?10/28/57?)
  ` $3 - Delimiter if passing an array

` <>QU is defined in the database as Char(34)

C_POINTER($1;$ObjectPtr;$ElementPtr)
C_TEXT($3;$0;$Text;$QU;$Delimiter;$ArrayName)
C_BOOLEAN($2)
C_LONGINT($Type;$Ndx;$TableNum;$FieldNum)

$ObjectPtr:=$1
$Type:=Type($ObjectPtr->)
If (Count parameters>=2)
  $AddQuotes:=$2
Else 
  $AddQuotes:=False
End if 

Case of 
  : (($Type=Is Alpha Field ) | ($Type=Is String Var ) | ($Type=Is Text ))  ` Just return the string
    $Text:=$ObjectPtr->
    $QU:=<>QU
    
  : (($Type=Is Real ) | ($Type=Is Integer ) | ($Type=Is LongInt ))  ` Convert to string
    $Text:=String($ObjectPtr->)
    $QU:=""
    
  : ($Type=Is Time )  ` Convert to string
    $Text:=String($ObjectPtr->)
    $QU:="?"
    
  : ($Type=Is Date )  ` Convert to string
    $Text:=String($ObjectPtr->)
    $QU:="!"
    
  : ($Type=Is Boolean )
    If ($ObjectPtr->)
      $Text:="True"
    Else 
      $Text:="False"
    End if 
    $QU:=""
    
  : (($Type=Boolean array ) | ($Type=Date array ) | ($Type=Integer array ) | ($Type=LongInt array ) | ($Type=Real array ) | ($Type=String array ) | ($Type=Text array ))
    $Delimiter:=$3
    $Text:=""
    For ($Ndx;1;Size of array($ObjectPtr->))
      RESOLVE POINTER($ObjectPtr;$ArrayName;$TableNum;$FieldNum)
      $ElementPtr:=Get pointer($ArrayName+"{"+String($Ndx)+"}")
      $Text:=$Text+$Delimiter+Str_Textize ($ElementPtr;$AddQuotes)
    End for 
    If (Length($Text)>0)
      $Text:=Substring($Text;2)
    End if 
    $AddQuotes:=False  ` We don't want quotes around the whole list even if the elements got them
    
  Else 
    $Text:=""  ` For the ones that can't be converted (ie, 2D arrays, BLOBs, etc.)
    $QU:=""
End case 

If ($AddQuotes)
  $Text:=$QU+$Text+$QU
End if 

$0:=$Text