home *** CD-ROM | disk | FTP | other *** search
/ Windoware / WINDOWARE_1_6.iso / miscprog / wzall / wz008.txt < prev    next >
Text File  |  1991-01-24  |  5KB  |  109 lines

  1.                                   INFORMIX SOFTWARE, INC., LENEXA, KS
  2.                             Wingz Technical Support Bulletin Number 008
  3.         
  4.         
  5.        Title:    Parsing an ACSII file
  6.        Date:     January 15, 1991
  7.         
  8.         
  9.        The following example script allows you to parse an ASCII file.  The 
  10.        script steps through the worksheet row by row, parsing each row into 
  11.        columns. To use this script, open the ASCII file to a Wingz worksheet. 
  12.        With that worksheet as the current window, execute this script from 
  13.        the script menu. 
  14.         
  15.        Sample Text:
  16.             "Text",12345.00,"January 12, 1991","12:12:12","555-55-5555"
  17.             "Text One",1111.11,"01/01/87","01:01:01","111-11-1111"
  18.         
  19.        Example Script:
  20.         
  21.        { ***this is only an example with no implied warrantees***
  22.          ***use at your own risk, make a backup, etc.*** }
  23.         
  24.        define len,matched,left_side,right_side,row,last_row
  25.         
  26.        repaint off
  27.        repaint selections off
  28.         
  29.        select last cell                        { find the last cell on sheet 
  30.        }            
  31.        last_row=row()                     { set last_row to row of the last 
  32.        cell }
  33.        select range a1                         { select cell a1 }
  34.        len=length(indirect (makecell(col(),row()))) { length of string in 
  35.        current cell }
  36.        matched=match(indirect (makecell(col(),row())),",",1)  
  37.                       { finds where to separate first and second columns }
  38.        for row=1 to last_row                   { loop thru all rows }
  39.         while matched<>0                  { a space or comma was found }
  40.             left_side=left(indirect(makecell(col(),row())),matched-1)
  41.                                           { left of comma }
  42.             if match(left(left_side,1),"""",1) { first character is a quote }
  43.                  matched=match(indirect(makecell(col(),row())),"""",2)
  44.                       { find the end quote to match beginning quote }
  45.                  left_side=mid(left(indirect(makecell(col(),row())),
  46.                            matched-1),1,matched-2)
  47.                       { left_side is everything between the two quotes }
  48.                  
  49.        right_side=right(indirect(makecell(col(),row())),len-matched-1)
  50.                       { right_side is to the right of the end quote and comma 
  51.        }
  52.             else                          { no quote at beginning of string }
  53.                  left_side=is_num(left(left_side,1))
  54.                                           { is left_side a number }
  55.                  
  56.        right_side=right(indirect(makecell(col(),row())),len-matched)
  57.                                           { right side of comma }
  58.             end if
  59.             put left_side into makecell(col(),row())          { put left into 
  60.        current cell }
  61.             put right_side into makecell(col()+1,row())       
  62.                                           { everything else in next column }
  63.             select range makecell(col()+1,row())         { select next column 
  64.        }
  65.             len=length(indirect (makecell(col(),row()))) 
  66.                                           { length of string in current cell 
  67.        }
  68.             matched=match(indirect (makecell(col(),row())),",",1) 
  69.                                 { find where to break into separate columns }
  70.         end while                    { exit the while loop once it has 
  71.        reached }
  72.         left_side=indirect(makecell(col(),row()))   { contents of last cell 
  73.        on row }
  74.         
  75.        left_side=if(match(left(left_side,1),"""",1),mid(left_side,1,length(le 
  76.        ft_side)-2),
  77.                       is_num(left(left_side,1)))              
  78.                  { if there are quotes, it's text, else check for value }
  79.         put left_side into makecell(col(),row())              { put left_side 
  80.        into cell }
  81.         select range makecell(1,row()+1)            { select next row, first 
  82.        column }
  83.         len=length(indirect (makecell(col(),row())))     { length of string 
  84.        in that cell }
  85.         matched=match(indirect (makecell(col(),row())),",",1) 
  86.                                           { find where to separate columns }
  87.        end for                            { repeat until no more rows of data 
  88.        }
  89.        repaint selections on
  90.        repaint on
  91.        repaint window
  92.         
  93.        function is_num(num)
  94.         if (num>=char(48) and num<=char(57))             
  95.                       { checks the ASCII value for num }                
  96.             and  exact(upper(left_side),lower(left_side))
  97.                       { compare upper and lower case of left_side }
  98.             and (contains(left_side,"-") = 0)       { does not have '-' in it 
  99.        }    
  100.             and (contains(left_side,"/") = 0)       { does not have '/' in it 
  101.        }    
  102.             and (contains(left_side,":") = 0)       { does not have ':' in it 
  103.        }              return value(left_side)    { it is a number return the 
  104.        value of the left_side }
  105.          else return left_side                 { not a number, return the 
  106.        string }
  107.          end if                           { end of check }
  108.        end function                       { end of function is_num }
  109.