Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Grumpfish Library 3.2 - <b>gloadarray()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
GLOADARRAY()

    This function loads an array from a text file.  It assumes that the
    array was previously saved with GSAVEARRAY().  I suppose that you
    could also call it to read in an array from any old text file, but
    the results may be totally ludicrous.

    Syntax

    GLOADARRAY(<array>, <filename>)

    Required Parameters

    <array> is the name of the array to be loaded.  Unlike GSAVEARRAY(),
    here you must enclose it in quotes. However, it does not need to be
    declared prior to calling the function. (See below for important
    Clipper 5.0 syntactical changes!)

    <filename> is the name of the file from which to load the array.

    Return Value

    GLOADARRAY() returns a logical value: True (.T.) if the load was
    successful; False (.F.) if it was not.  Reasons for it failing would
    be related to an inability to create the file (probably due to lack
    of available file handles) or inability to read from the file (in
    which case your guess is as good as mine).

    Notes

    Because GSAVEARRAY() writes the length of the array to the beginning
    of the text file, it is easy enough for GLOADARRAY() to determine
    the length of the target array.  GLOADARRAY() then declares the
    array as PUBLIC to that length, and reads in its contents a line at
    a time.

    Clipper 5.0 Notes

    The 5.0 version of this function is somewhat different. GLOADARRAY()
    now returns an array rather than a logical value.  This means that
    we are no longer dependent on the dreaded macro, and you thus need
    not pass the name of the array in quotes.  However, it means that we
    have to figure out another way to test for whether the load was
    successful or not.  No problem... with the preprocessor, we are able
    to pull it off.  But to avoid a cyclic reference, we have to refer
    to this function by a slightly different name, LOADARRAY(). See
    below for an example.  And have a look at GRUMP.CH to see how the
    preprocessor translates your LOADARRAY() call -- it is rather
    instructive.  Also note that the 5.0 version will handle nested
    arrays -- the 5.0 example below illustrates how to display the
    contents of nested arrays.  WARNING: code blocks cannot be saved
    to text files!!

    Sample Usage

    *** Summer '87                       
    IF GLOADARRAY('myarray', 'array.txt')
       FOR xx = 1 TO LEN(myarray)        
          ? myarray[xx]                  
       NEXT                              
    ENDIF                                

    /* Clipper 5.0 - will show subarrays */  
    #include "grump.ch"                      
    IF LOADARRAY(myarray, 'array.txt')       
       aeval(myarray, { | a | showit(a) } )  
    ENDIF                                    
    |                                        
    function showit(element)                 
    static level := 0                        
    if valtype(element) != 'A'               
       if level > 0                          
          qqout(chr(195))                    
          qqout(replicate(chr(196), level*3))
       else                                  
          qqout(chr(179))                    
       endif                                 
       qqout(element)                        
       qqout(CRLF)                           
    else                                     
       level++                               
       aeval(element, { | b | showit(b) } )  
       level--                               
    endif                                    
    return nil                               

See Also: GSAVEARRAY() GFREADLINE()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson