home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************
- FUNCTION ARSAVE (arr_name, arr_file)
- *****************************************************************
-
- * Saves an array to a disk file
-
- * Copyright(c) 1991 -- James Occhiogrosso
-
- LOCAL arr_string, cntr, str_num, dec_pos, elem_delim
-
- * Define element delimiter
- elem_delim = CHR(255)
-
- * Return error if any parameter is incorrect.
- IF PCOUNT() != 2 .OR. VALTYPE(arr_file) != 'C' .OR. ;
- VALTYPE(arr_name) != 'A'
- RETURN .F.
- ENDIF
-
- * If extension is not passed, default to .ARR
- IF AT('.', arr_file) = 0
- arr_file = arr_file + '.ARR'
- ENDIF
-
- * Put length of the array at start of array string.
- arr_string = PADL(LEN(arr_name),4) + elem_delim
-
- * Add each element and the delimiter to the string.
- FOR cntr = 1 TO LEN(arr_name)
- elem_type = VALTYPE(arr_name[cntr])
-
- IF elem_type = 'U'
- * Element is undefined.
- arr_string = arr_string + 'U' + elem_delim
- ELSEIF elem_type = 'C'
- * Element is character - No adjustment required.
- arr_string = arr_string + 'C' + arr_name[cntr] + elem_delim
- ELSEIF elem_type = 'D'
- * Element is a date - Convert to a character string
- arr_string = arr_string + 'D' + DTOC(arr_name[cntr]) + ;
- elem_delim
- ELSEIF elem_type = 'L'
- * Element is logical - Convert to T or F character
- arr_string = arr_string + 'L' + IF(arr_name[cntr], ;
- 'T', 'F') + elem_delim
- ELSEIF elem_type = 'N'
- * Element is a number. Convert to left justified string
- str_num = LTRIM(STR(arr_name[cntr]))
- dec_pos = AT('.', str_num)
-
- IF dec_pos = 0
- * No decimal positions, put zero in last 3 bytes
- arr_string = arr_string + 'N' + PADL(LEN(str_num),3) ;
- + ' 0' + str_num + elem_delim
- ELSE
- * Decimal positions exist, save them in last 3 bytes
- arr_string = arr_string + 'N' + ;
- PADL(LEN(str_num),3) + ;
- PADL(LEN(str_num)-dec_pos,3) + ;
- str_num + elem_delim
- ENDIF
- ENDIF
- NEXT
-
- * Write the file and return .T. if successful.
- RETURN( MEMOWRIT(arr_file, arr_string) )
-
-