Get Table Field Pointer

This is like 4D's GET POINTER except that it's specifically written to work with tables and fields instead of variables. You can pass a table name with or without brackets, but a field needs to be in the [Table]Field format.
  ` GetTableFieldPointer
  ` Returns a pointer to the table or field pointer string passed
  ` $1 - Table or Field name - Table: Orders or [Orders]; Field: [Orders]Address
  ` Written by Tom Dillon

C_LONGINT($RBPos;$TableNum;$i)
C_POINTER($0;$TablePtr;$FieldPtr)
C_TEXT($1;$PointerStr;$TableStr;$FieldStr;$Name)
C_BOOLEAN($IsField)

$PointerStr:=$1

If ($PointerStr#"")
  While (Substring($PointerStr;1;1)<"A")  ` Gets rid of leading junk
    $PointerStr:=Substring($PointerStr;2)
  End while 
  
  If ($PointerStr#"")
    If ($PointerStr[[1]]="[")  ` Beginning of a table in [Table] format
      $PointerStr:=Substring($PointerStr;2)
    End if 
    $IsField:=False
    $RBPos:=Position("]";$PointerStr)  ` Ending of a table in [Table] format
    If ($RBPos>0)  ` Position of right bracket indicates that [Table] exists
      $TableStr:=Substring($PointerStr;1;$RBPos-1)
      If (Length($PointerStr)>$RBPos)  ` There's more than just a table. A field exists.
        $FieldStr:=Substring($PointerStr;$RBPos+1)
        $IsField:=True
      End if 
    Else   ` No ] so it's just a table
      $TableStr:=$PointerStr
    End if   ` ($RBPos>0)
    
    $TableNum:=0
    For ($i;1;Count tables)
      $Name:=Table name($i)
      If ($Name=$TableStr)
        $TablePtr:=Table($i)
        $TableNum:=$i
        $i:=Count tables
      End if   ` ($i;1;Count tables)
    End for   ` ($i;1;Count tables)
    
    If (($IsField) & ($TableNum#0))
      For ($i;1;Count fields($TableNum))
        $Name:=Field name($TableNum;$i)
        If ($Name=$FieldStr)
          $FieldPtr:=Field($TableNum;$i)
          $i:=Count fields($TableNum)
        End if 
      End for   ` ($i;1;Count fields($TableNum))
    End if   ` (($IsField) & ($TableNum#0))
  End if   ` ($PointerStr # "")
End if   ` ($PointerStr # "")

If ($IsField)
  $0:=$FieldPtr
Else 
  $0:=$TablePtr
End if