home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY5 / LSTRAN.ZIP / LSTRANGE.BAS < prev    next >
BASIC Source File  |  1990-06-08  |  3KB  |  112 lines

  1. $compile EXE
  2. $error all off
  3. $lib all off
  4. $option autodim off
  5. $option cntlbreak off
  6. $float emulate
  7. $stack 2048
  8. $include "PBSTD.INC"         ' Standard named constants
  9. $include "FILEUTIL.INC"      ' Some standard routines
  10.  
  11. Title$ = "    LstRange.EXE               Michael E. Flenniken               6-6-90"
  12. if instr(command$, " ") then
  13.     FileName$ = left$(command$, instr(command$, " "))
  14. else
  15.     FileName$ = command$
  16. end if
  17.  
  18. WksHandle% = Open123% (FileName$)
  19. if WksHandle% = %False then
  20.     ? Title$
  21.     ?
  22.     ? "    Syntax:  LSTRANGE [<path>]<filespec>"
  23.     ? "    where <filespec> is the file name of the spreadsheet to read.  If no"
  24.     ? "             extension is specified, LSTRANGE will look for <filespec>.WKS "
  25.     ? "             first, and if unseccessful, will look for <filespec>.WK1"
  26.     ? "          <path> is an optional DOS path specification.
  27.     ?
  28.     ? "Unable to open file"
  29.     END
  30. end if
  31.  
  32. call StdOut (Title$, 13)
  33. call StdOut ("", 13)
  34. call StdOut ("    List of named ranges for " +ucase$(FileName$) +":", 13)
  35.  
  36. do
  37.     call Read123Rec
  38.     if cvi(RecType$$) = %RangeName1 _
  39.       or cvi(RecType$$) = %RangeName2 then
  40.         Col1% = cvi(mid$(RecData$$, 17, 2))
  41.         Row1% = cvi(mid$(RecData$$, 19, 2))
  42.         Col2% = cvi(mid$(RecData$$, 21, 2))
  43.         Row2% = cvi(mid$(RecData$$, 23, 3))
  44.         NameOut$ = using$("    \              \  ", extract$(RecData$$, chr$(0)))
  45.         AddrOut$ = left$(CellAddress$ (Col1%, Row1%) +".." _
  46.                         +CellAddress$ (Col2%, Row2%) +space$(16), 16)
  47.         call StdOut (NameOut$, 0)
  48.         call StdOut (AddrOut$, 0)
  49.         if Column% = 2 then
  50.             call StdOut ("", 13)
  51.             Column% = 1
  52.         else
  53.             call StdOut (space$(2), 0)
  54.             Column% = 2
  55.         end if
  56.     end if
  57. loop until eof(1)
  58. close WksHandle%
  59.  
  60. END
  61.  
  62. '************************************************************************
  63. %Signature123 =  0
  64. %RangeName1   = 11
  65. %RangeName2   = 71
  66.  
  67. sub Read123Rec
  68.     shared Record123$$, RecType$$, RecLength$$, RecData$$
  69.  
  70. get$ #1, 4, Record123$$
  71. get$ #1, cvi(RecLength$$), RecData$$
  72.  
  73. end sub
  74.  
  75.  
  76. function CellAddress$ (Col%, Row%)
  77.  
  78. if Col% > 25 then
  79.     Cell$ = chr$(Col% \26 +64)
  80. end if
  81. CellAddress$ = Cell$ +chr$(Col% mod 26 +65) +mid$(str$(Row% +1), 2)
  82.  
  83. end function
  84.  
  85.  
  86. function Open123% (FileToOpen$)
  87.     local FileName$, WksHandle%
  88.     shared Record123$$, RecType$$, RecLength$$, RecData$$
  89.  
  90. FileName$ = DefaultExt$ (FileToOpen$, "WKS")     ' Validate file name
  91. if not Exists% (FileName$) then
  92.     FileName$ = DefaultExt$ (FileToOpen$, "WK1")
  93.     if not Exists% (FileName$) then
  94.         Open123% = %False
  95.     end if
  96. end if
  97. WksHandle% = GetHandle% (FileName$, "Binary")
  98. if WksHandle% < 1 then
  99.     Open123% = %False
  100.     exit function
  101. end if
  102. map Record123$$ * 259, 2 as RecType$$, 2 as RecLength$$, 255 as RecData$$
  103. call Read123Rec
  104. if left$(Record123$$, 6) = chr$(%Signature123, 0, 2, 0, 4, 4) _
  105.   or left$(Record123$$, 6) = chr$(%Signature123, 0, 2, 0, 6, 4) then
  106.     Open123% = WksHandle%
  107. else
  108.     Open123% = %False
  109. end if
  110.  
  111. end function
  112.