KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method to programmatically determine the number of lines in a method
PRODUCT: 4D | VERSION: 15.1 | PLATFORM: Mac & Win
Published On: June 14, 2016

Below is an utility method to programmatically determine the number of lines in a method. The method takes in the path to the method determined by METHOD GET PATH.

//Method Name: UTIL_METHOD_COUNT_LINES
//Gets number of lines in a given method
//Params: $1 - path to method
//Return: $0 - number of lines in given method
C_TEXT($1;$path;$code)
C_LONGINT($0;$count;$position)

If (Count parameters>=1)
   $path:=$1
   METHOD GET CODE($path;$code)

   $pattern:="\r"
   $count:=0
   $position:=Position($pattern;$code;$position+1;*)
   While ($position#0)
      $count:=$count+1
      $position:=Position($pattern;$code;$position+1;*)
   End while
   $0:=$count
End if


Below is an example of calling the method:
$methodPath:=METHOD Get path(Path project method;"Method1")
$numLines:=UTIL_METHOD_COUNT_LINES($path)