home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / libbasic / guide.txt < prev    next >
Text File  |  1994-04-23  |  8KB  |  282 lines

  1.  
  2. The GWBASIC to Liberty BASIC Survival Guide
  3. -----------------------------------------------
  4.  
  5. Liberty BASIC is designed to be a lot like GWBASIC, but there are
  6. differences.  Some of these differences are incompatibilities, and
  7. some are enhancements.
  8.  
  9. Here you will find information about:
  10.  
  11.   PRINT                 File Handles
  12.   INPUT                 INPUT$()
  13.   Variable Names        Boolean Operators
  14.   Variable Types        TIME$(), DATE$()
  15.   Line Numbers          Random Numbers
  16.   DIM                   READ, DATA, RESTORE
  17.   ELSEIF...ENDIF
  18.  
  19.  
  20. PRINT
  21. ---------------------------------------------------------------------
  22.  
  23. PRINT is -almost- the same.  The comma cannot be used as a formatter.
  24. For example:
  25.  
  26.     print a, b, c
  27.  
  28.   is valid in GWBASIC, but not in Liberty BASIC
  29.  
  30. Also, PRINT USING isn't supported, but there is a using( function
  31. instead.
  32.  
  33.   GWBASIC:        print using "The total is #####.##", ttl
  34.   Liberty BASIC:  print "The total is "; using("####.##", ttl)
  35.  
  36. GWBASIC inserts spaces before and after numbers (called padding) when
  37. it prints them.  Liberty BASIC doesn't pad, but if you want to, you
  38. can add padding spaces in your code.
  39.  
  40.  
  41. INPUT
  42. ---------------------------------------------------------------------
  43.  
  44. GWBASIC permits this:
  45.  
  46.     input "Give me the next number"; n(x)
  47.  
  48. In Liberty BASIC, you must do this:
  49.  
  50.     input "Give me the next number"; n
  51.     n(x) = n
  52.  
  53. GWBASIC automatically adds a question mark and an extra space onto the
  54. end of the prompt (using above as example: Give me the next number? _).
  55. Liberty BASIC doesn't do this.  For example:
  56.  
  57.     input "Give me the next number >"; n
  58.  
  59.   appears as:
  60.  
  61.     Give me the next number >_
  62.  
  63.   using Liberty BASIC.  If desired, simply changing the > to a ? will
  64.   produce the GWBASIC-like effect.
  65.  
  66.  
  67.  
  68. Variable Names
  69. ---------------------------------------------------------------------
  70.  
  71. Liberty BASIC accepts GWBASIC variable names.  But it also lets you
  72. use upper and lower case letters.
  73.  
  74.   someTime   and   sometime
  75.  
  76.   are considered different variables in Liberty BASIC.
  77.  
  78.  
  79.  
  80. Variable Types
  81. ---------------------------------------------------------------------
  82.  
  83. Liberty BASIC only supports two variable types, numeric and string.
  84.  
  85. The numeric variable holds either an integer or real value, and in
  86. this case Liberty BASIC optimizes automatically.  If a real loses
  87. its non-integer part through some calculation, then Liberty BASIC
  88. converts it into an integer to speed up operations.  Integers can be
  89. enormously large (see factorial.bas).  Reals are single precision.
  90.  
  91. The string variable holds a character string that can be as large as
  92. available memory.
  93.  
  94. NOTE:
  95.  
  96.   Variables are actually untyped in Liberty BASIC.  A string variable
  97.   name can contain a numeric value, and a numeric variable name can
  98.   contain a string.  But arrays ARE typed, just as in other BASICs.
  99.  
  100.  
  101. Line Numbers
  102. ---------------------------------------------------------------------
  103.  
  104. Liberty BASIC lets you use the conventional line numbers if you like.
  105. You can also choose not to use them, and use descriptive branch labels
  106. instead.  For example:
  107.  
  108. In GWBASIC:
  109.  
  110.   10 print "Let's loop!"
  111.   20 x = x + 1
  112.   30 print x
  113.   40 if x < 10 then 20
  114.   50 print "Done."
  115.   60 end
  116.  
  117. In Liberty BASIC:
  118.  
  119.      print "Let's loop!"
  120.   [mainLoop]
  121.      x = x + 1
  122.      print x
  123.      if x < 10 then [mainLoop]
  124.      print "Done."
  125.      end
  126.  
  127.   You can see here that instead of jumping to line 20, as in the first
  128.   example, we can instead jump to [mainLoop].  You can name your
  129.   branch points and subroutines whatever you like.  They need to start
  130.   and end with [ and ], respectively, and they can't have any spaces.
  131.  
  132.   Legal branch labels:
  133.  
  134.     [mainLoop]
  135.     [loop1]
  136.     [exceptionHandler]
  137.  
  138.   Illegal branch labels:
  139.  
  140.     [main loop]
  141.     mainLoop
  142.  
  143.  
  144.  
  145. DIM
  146. ---------------------------------------------------------------------
  147.  
  148. The DIM statement can only dimension ONE array per statement, so
  149. instead of:
  150.  
  151.     dim a(20), b(20), c(20)
  152.  
  153.   do this:
  154.  
  155.     dim a(20) : dim b(20) : dim c(20)
  156.  
  157.  
  158.  
  159. ELSEIF...ENDIF
  160. ---------------------------------------------------------------------
  161.  
  162. Liberty BASIC supports IF...THEN...ELSE, but not the ELSEIF...ENDIF
  163. combinations.
  164.  
  165.  
  166.  
  167. File Handles
  168. ---------------------------------------------------------------------
  169.  
  170. GWBASIC lets you use only numbers as file handles.  Liberty BASIC lets
  171. you use numbers, and it lets you use letters also.
  172.  
  173.   open "autoexec.bat" for input as #1 ' GWBASIC
  174.  
  175.   open "autoexec.bat" for input as #autoexec  ' Liberty BASIC
  176.  
  177. Now here's the catch.  Whenever you reference the file handle, you
  178. MUST use have a # in front of it.
  179.  
  180.   if eof(1) > 0 then 10020 ' GWBASIC
  181.  
  182.   if eof(#autoexec) > 0 then [reachedEnd]  ' Liberty BASIC
  183.  
  184. Additionally:
  185.  
  186.   print # 1, "buffers = 30"  ' this works fine in GWBASIC
  187.          ^--------this extra space not allowed in Liberty BASIC
  188.  
  189.  
  190.  
  191. INPUT$()
  192. ---------------------------------------------------------------------
  193.  
  194.   In GWBASIC, there are two uses for INPUT$().
  195.   1) To fetch x number of characters from a sequential file
  196.   2) To fetch x number of characters from the keyboard
  197.  
  198.     a$ = input$(1, 10) 'Fetch 10 characters from file handle 1
  199.     a$ = input$(1) 'Fetch 1 character from the keyboard
  200.  
  201.   In Liberty BASIC, there are also two uses for INPUT$().
  202.   1) To fetch x number of characters from a sequential file
  203.   2) To fetch only 1 character from the keyboard
  204.  
  205.     a$ = input$(#1, 10) 'Fetch 10 characters from file handle #1
  206.     a$ = input$(1) 'Fetch a single character from the keyboard
  207.  
  208. Using input$(1) to read from the keyboard only works in the main
  209. window, and not with any windows created using OPEN.
  210.  
  211.  
  212. Boolean Operations
  213. ---------------------------------------------------------------------
  214.  
  215. Liberty BASIC supports AND & OR, much like GWBASIC.  These are
  216. typically used in IF...THEN statements like so:
  217.  
  218.   if x < limit and userAbort = 0 then [mainLoop]
  219.  
  220.   if (c$ >= "A" and c$ <= "Z") or (c$ >= "a" and c$ <= "z") then [inRange]
  221.  
  222. However, bitwise ANDing and ORing aren't supported.  If numbers are
  223. ANDed or ORed, then a Zero is always a Boolean False, and any
  224. Non-Zero is always a Boolean True, and 0 and 1 are the only possible
  225. return values.  Consider:
  226.  
  227.   print 1 and 1         ' produces 1
  228.   print 1 and 0         ' produces 0
  229.   print 1 or 0          ' produces 1
  230.   print 0 or 23         ' produces 1
  231.   print -5 and 0        ' produces 1
  232.  
  233. GWBASIC supports bitwise operations such as:
  234.  
  235.   print 8 or 16         ' produces 24
  236.   print 7 and 15        ' produces 7
  237.  
  238. Liberty BASIC doesn't support this format.
  239.  
  240.  
  241.  
  242. TIME$(), DATE$()
  243. ---------------------------------------------------------------------
  244.  
  245. In GWBASIC you get the time or date by using the special variables
  246. time$ and date$.  For example:
  247.  
  248.   print time$           'this produces the current time
  249.   print date$           'this produces the current date
  250.  
  251. In Liberty BASIC it looks like this:
  252.  
  253.   print time$()         'this produces the current time
  254.   print date$()         'this produces the current date
  255.  
  256.  
  257.  
  258. Random Numbers
  259. ---------------------------------------------------------------------
  260.  
  261. In Liberty BASIC, random numbers between 0 and 1 are generated with
  262. the expression RND(1).  GWBASIC will produce the same result with
  263. that expression.  Apparently GWBASIC also lets you substitute just
  264. RND, and it assumes the (1) part in this case.  Both of these lines
  265. produce the same result in GWBASIC.
  266.  
  267.   x = int(rnd(1)*10)+1  ' this format works with both BASICs
  268.   x = int(rnd*10)+1     ' this format doesn't
  269.  
  270. The second line is not permitted in Liberty BASIC.  It will always
  271. equal 1, because rnd will be parsed as a numeric variable, and will
  272. equal zero, unless it is assigned some other value.
  273.  
  274.  
  275. READ, DATA, RESTORE
  276. --------------------------------------------------------------------
  277.  
  278. Even though Liberty BASIC 0.9x supports READ, DATA, and RESTORE,
  279. versions 1.x don't yet.  This will be added on later.
  280.  
  281.  
  282.