Liberty Basic is develeopped by Carl Gundel
Original Newsletter compiled by Alyce Watson and Brosco
Translation to HTML: Raymond Roumeas

The Liberty Basic Newsletter - Issue #64 - FEB 2000

© 2000, Cliff Bros and Alyce Watson

All Rights Reserved

 

Brosco and Alyce have written a Book for Liberty BASIC, which is available in electronic form on a CDROM. For details: http://alyce.50megs.com/sss/cd.htm


In this issue:

  1. The Edit Menu
  2. Playing wavs
  3. A new way to use the filedialog
  4. Using ascii characters in commands -- copyrighting our code

In future issues:


1. THE EDIT MENU

 

We've mentioned in an earlier newsletter that placing a texteditor control in a window automatically gives the window a complete EDIT menu. We don't need to do a thing!

This same EDIT menu can be accessed by clicking the right mouse button anywhere inside of the texteditor control. This is not known by every Liberty BASIC programmer, and it is certainly not known by our program's potential users, so let's tell them. We'll add a tooltip to the texteditor control with a message about the right-click EDIT menu.

Refer to newsletter #60 for more detailed information on adding tooltips. Thanks again, Brent Thorn, for sharing this method!

 
'** NEW **
    struct toolinfo16, cbSize as word, uFlags as word,_
        hwnd as word, uId as word, x as word, y as word,_
        w as word, h as word, _
        hInst as word, lpstrText$ as ptr
 
    toolinfo16.cbSize.struct = 22
    toolinfo16.uFlags.struct = TTF.IDISHWND or TTF.SUBCLASS
    toolinfo16.hwnd.struct = h
    toolinfo16.uId.struct = hwnd(#1.t)
    toolinfo16.hInst.struct = hInstance
    toolinfo16.lpstrText$.struct = "Right click here for an edit menu."
    calldll #user, "SendMessage", hwndTT as word, TTM.ADDTOOL as word, _
    0 as word, toolinfo16 as struct, re as long
 


2. PLAYING WAVS

 

Liberty BASIC makes it very easy to play wav files. Here is the syntax, as copied from the LB helpfile:

PLAYWAVE "filename" [, mode ]

Description:

Plays a *.wav sound file as specified in filename. If mode is specified, it must be one of the modes specifed below:

The mode, sync, or synch will halt all program action until the wav is done playing. This is the default. There has been some discussion amongst LBers recently about using wavs to generate program delays. A blank wav can be used, if no sound is wanted.

The mode,async, or asynch will play the wav, but will allow the program to continue execution.

The mode, loop will play the wave over and over until the command playwave "" is issued. (This command will also stop a wav that is being played async.)

Here is a sample wav command:

PLAYWAVE "c:\wavs\chicken.wav" , asynch

Since we often use wavs as part of our Liberty BASIC programs, let's add a wav previewer to our arsenal of programming tools in the open source editor.


3. A NEW WAY TO USE THE FILE DIALOG

Let's define some new variables for wav file play in our open source editor:

'wavPath$           path to last wav played
'wavFile$           name of wav file to play
'slash              counter variable to separate wav path from filename

Let's add the wav previewer to the tools menu:

'** NEW **
menu #1, "&Tools",_
    "&Branch Labels",[branchlabels],_
    "Bit&map Preview",[bmp],_
    "&Wav Preview",[wav]

It is a nice touch to open a file dialog in the directory that was chosen mose recently by the user. This saves a lot of time in navigating the file dialogs. We'll need to parse the file name to separate the drive/path informtion from the file name. We'll use an index variable, called "slash" to check the file name string for the right-most backslash. When we reach it, we know we have reached the spot in the file name that divides the path information from the name information. We'll set the index counter, "slash" equal to the length of the filename to begin. We'll use LB's INSTR() function to check for the "\" character, starting at the end of the file name. If it returns 0, then there is no backslash, so we will decrement (a fancy word for decrease value) the counter variable, "slash" by one and try again. While we do not find a backslash "\", we'll keep looping (wend). When the function returns a value other than 0, then we know we've found a backslash:

lash=len(wavFile$)
while instr(wavFile$, "\", slash)=0
slash=slash-1
wend

Now, the variable "slash" contains the location of the right-most backslash. We know that everything to the left of this location is the drive/path information, and everything to the right is the file name. We'll put the path information into the variable, "wavPath$".

wavPath$=left$(wavFile$,slash)

Now that we've stored the path information for the next time a user wants to open a wav, we can play the currently selected wav file:

playwave wavFile$,async

We can do some error checking also. The first wav opened will not have a set value for wavPath$, so we can set that to be DefaultDir$.

if wavPath$="" then wavPath$=DefaultDir$

Now, we'll let the user choose a wav file to preview. If the user doesn't choose a file (presses CANCEL) we can abort the wav playing operation and return to the input loop. At this time, we also stop any wavs that may already be playing with the command: playwave ""

 
    filedialog "Open WAV file",wavPath$+"\*.WAV",wavFile$
    if wavFile$="" then
        playwave ""
        goto [loop]
    end if
 

Right now, you are probably wondering how this is a NEW way to use the filedialog. So far, it is not new. Look at the following code for our wav previewer. This is the entire routine:

'** NEW **
[wav]
    if wavPath$="" then wavPath$=DefaultDir$
    filedialog "Open WAV file",wavPath$+"\*.WAV",wavFile$
    if wavFile$="" then
        playwave ""
        goto [loop]
    end if
 
    slash=len(wavFile$)
        while instr(wavFile$, "\", slash)=0
            slash=slash-1
        wend
    wavPath$=left$(wavFile$,slash)
    playwave wavFile$,async
    goto [wav]
 

The NEW part is in the last line, "goto [wav]". When the chosen wav has been played, the program continues its operation by going back to the start of the wav playing routine, not to the input loop. The program returns to the input loop only when the user presses CANCEL in the filedialog box.

This little trick saved us quite a lot of code! We are asking the filedialog itself to act as the dialog window for our wav player, so we do not need to write the code to open a window! After a user has chosen a wav, the filedialog immediately opens again to allow the choice of the next wav.

This author thought she was quite clever in "inventing" this method. Oops. Have a look at the sample programs that come packaged with Liberty BASIC. Load up "player.bas". Does it look familiar? There is a wealth of information in these sample programs, and in the helpfile. It's a good idea to review these every now and again. Something just might pop out at us that we can really use!


4. USING ASCII CHARACTERS IN COMMANDS-COPYRIGHTING OUR CODE

 

ASCII = American Standard Code for Information Interchange

There are 256 ascii characters. They are numbered from 0 - 255. If we want to know the ascii code for a character, we use the chr$() function.

Print chr$("t")       

produces

116
 

If we want to print a character by using its ascii code, we use the asc() function.

Print asc(116)

produces

t
 

There are a number of characters that we can access with the chr$() function that do not produce printable characters. For instance, the character chr$(10) will cause a line feed and chr$(13) is the code for a carriage return. We discussed the tab character, chr$(9) in the previous newsletter. These characters will not show on the screen when we use them; they are really instructions for formatting and display.

We use some of these in our Liberty BASIC commands. A NOTICE message displays the title "Notice". We can specify our own title, by setting off the title text from the message text with a chr$(13). Here's an example:

notice "Error" + chr$(13) + "Invalid command!"

The word "Error" will appear on the titlebar of the notice dialog, and the message "Invalid command!" will be contained within the notice window. If we want to break text in our notice command at locations of our own choice, we can add more chr$(13) like this:

notice "Hello"+chr$(13)+"One"+chr$(13)+"Two"+chr$(13)+"Three"

The dialog will contain the text "Hello" on the titlebar. The message itself will look like this:

	One
	Two
	Three
 

To see the way all ascii characters, 0-255 will display on the screen, use this little program:

for i = 0 to 255
        print i;
        print "   "+chr$(i)
    next i
 

You will see all of the usual alpha-numerics and punctuation marks in the printout. You will also seem some blank boxes that appear when an unprintable character is accessed. You will also see a lot of unusual-looking characters. You won't find a key on the keyboard that allows you to type a " £ " character! Have a look at the following list:

 
ASCII    1 is:  
ASCII    2 is:  
ASCII    3 is:  
ASCII    4 is:  
ASCII    5 is:  
ASCII    6 is:  
ASCII    7 is:  
ASCII    8 is:  
ASCII    9 is: (tab) 	
ASCII   10 is: {line feed}
ASCII   11 is:  
ASCII   12 is:  
ASCII   13 is: {carriage return}
ASCII   14 is:  
ASCII   15 is:  
ASCII   16 is:  
ASCII   17 is:  
ASCII   18 is:  
ASCII   19 is:  
ASCII   20 is:  
ASCII   21 is:  
ASCII   22 is:  
ASCII   23 is:  
ASCII   24 is:  
ASCII   25 is:  
ASCII   26 is:  
ASCII   27 is:  
ASCII   28 is:  
ASCII   29 is:  
ASCII   30 is:  
ASCII   31 is:  
ASCII   32 is:
ASCII   33 is:  !
ASCII   34 is:  "
ASCII   35 is:  #
ASCII   36 is:  $
ASCII   37 is:  %
ASCII   38 is:  &
ASCII   39 is:  '
ASCII   40 is:  (
ASCII   41 is:  )
ASCII   42 is:  *
ASCII   43 is:  +
ASCII   44 is:  ,
ASCII   45 is:  -
ASCII   46 is:  .
ASCII   47 is:  /
ASCII   48 is:  0
ASCII   49 is:  1
ASCII   50 is:  2
ASCII   51 is:  3
ASCII   52 is:  4
ASCII   53 is:  5
ASCII   54 is:  6
ASCII   55 is:  7
ASCII   56 is:  8
ASCII   57 is:  9
ASCII   58 is:  :
ASCII   59 is:  ;
ASCII   60 is:  <
ASCII   61 is:  =
ASCII   62 is:  >
ASCII   63 is:  ?
ASCII   64 is:  @
ASCII   65 is:  A
ASCII   66 is:  B
ASCII   67 is:  C
ASCII   68 is:  D
ASCII   69 is:  E
ASCII   70 is:  F
ASCII   71 is:  G
ASCII   72 is:  H
ASCII   73 is:  I
ASCII   74 is:  J
ASCII   75 is:  K
ASCII   76 is:  L
ASCII   77 is:  M
ASCII   78 is:  N
ASCII   79 is:  O
ASCII   80 is:  P
ASCII   81 is:  Q
ASCII   82 is:  R
ASCII   83 is:  S
ASCII   84 is:  T
ASCII   85 is:  U
ASCII   86 is:  V
ASCII   87 is:  W
ASCII   88 is:  X
ASCII   89 is:  Y
ASCII   90 is:  Z
ASCII   91 is:  [
ASCII   92 is:  \
ASCII   93 is:  ]
ASCII   94 is:  ^
ASCII   95 is:  _
ASCII   96 is:  `
ASCII   97 is:  a
ASCII   98 is:  b
ASCII   99 is:  c
ASCII  100 is:  d
ASCII  101 is:  e
ASCII  102 is:  f
ASCII  103 is:  g
ASCII  104 is:  h
ASCII  105 is:  i
ASCII  106 is:  j
ASCII  107 is:  k
ASCII  108 is:  l
ASCII  109 is:  m
ASCII  110 is:  n
ASCII  111 is:  o
ASCII  112 is:  p
ASCII  113 is:  q
ASCII  114 is:  r
ASCII  115 is:  s
ASCII  116 is:  t
ASCII  117 is:  u
ASCII  118 is:  v
ASCII  119 is:  w
ASCII  120 is:  x
ASCII  121 is:  y
ASCII  122 is:  z
ASCII  123 is:  {
ASCII  124 is:  |
ASCII  125 is:  }
ASCII  126 is:  ~
ASCII  127 is:  
ASCII  128 is:  
ASCII  129 is:  
ASCII  130 is:  
ASCII  131 is:  
ASCII  132 is:  
ASCII  133 is:  
ASCII  134 is:  
ASCII  135 is:  
ASCII  136 is:  
ASCII  137 is:  
ASCII  138 is:  
ASCII  139 is:  
ASCII  140 is:  
ASCII  141 is:  
ASCII  142 is:  
ASCII  143 is:  
ASCII  144 is:  
ASCII  145 is:  
ASCII  146 is:  
ASCII  147 is:  
ASCII  148 is:  
ASCII  149 is:  
ASCII  150 is:  
ASCII  151 is:  
ASCII  152 is:  
ASCII  153 is:  ™
ASCII  154 is:  
ASCII  155 is:  
ASCII  156 is:  
ASCII  157 is:  
ASCII  158 is:  
ASCII  159 is:  
ASCII  160 is:   
ASCII  161 is:  ¡
ASCII  162 is:  ¢
ASCII  163 is:  £
ASCII  164 is:  ¤
ASCII  165 is:  ¥
ASCII  166 is:  ¦
ASCII  167 is:  §
ASCII  168 is:  ¨
ASCII  169 is:  ©
ASCII  170 is:  ª
ASCII  171 is:  «
ASCII  172 is:  ¬
ASCII  173 is:  ­
ASCII  174 is:  ®
ASCII  175 is:  ¯
ASCII  176 is:  °
ASCII  177 is:  ±
ASCII  178 is:  ²
ASCII  179 is:  ³
ASCII  180 is:  ´
ASCII  181 is:  µ
ASCII  182 is:  ¶
ASCII  183 is:  ·
ASCII  184 is:  ¸
ASCII  185 is:  ¹
ASCII  186 is:  º
ASCII  187 is:  »
ASCII  188 is:  ¼
ASCII  189 is:  ½
ASCII  190 is:  ¾
ASCII  191 is:  ¿
ASCII  192 is:  À
ASCII  193 is:  Á
ASCII  194 is:  Â
ASCII  195 is:  Ã
ASCII  196 is:  Ä
ASCII  197 is:  Å
ASCII  198 is:  Æ
ASCII  199 is:  Ç
ASCII  200 is:  È
ASCII  201 is:  É
ASCII  202 is:  Ê
ASCII  203 is:  Ë
ASCII  204 is:  Ì
ASCII  205 is:  Í
ASCII  206 is:  Î
ASCII  207 is:  Ï
ASCII  208 is:  Ð
ASCII  209 is:  Ñ
ASCII  210 is:  Ò
ASCII  211 is:  Ó
ASCII  212 is:  Ô
ASCII  213 is:  Õ
ASCII  214 is:  Ö
ASCII  215 is:  ×
ASCII  216 is:  Ø
ASCII  217 is:  Ù
ASCII  218 is:  Ú
ASCII  219 is:  Û
ASCII  220 is:  Ü
ASCII  221 is:  Ý
ASCII  222 is:  Þ
ASCII  223 is:  ß
ASCII  224 is:  à
ASCII  225 is:  á
ASCII  226 is:  â
ASCII  227 is:  ã
ASCII  228 is:  ä
ASCII  229 is:  å
ASCII  230 is:  æ
ASCII  231 is:  ç
ASCII  232 is:  è
ASCII  233 is:  é
ASCII  234 is:  ê
ASCII  235 is:  ë
ASCII  236 is:  ì
ASCII  237 is:  í
ASCII  238 is:  î
ASCII  239 is:  ï
ASCII  240 is:  ð
ASCII  241 is:  ñ
ASCII  242 is:  ò
ASCII  243 is:  ó
ASCII  244 is:  ô
ASCII  245 is:  õ
ASCII  246 is:  ö
ASCII  247 is:  ÷
ASCII  248 is:  ø
ASCII  249 is:  ù
ASCII  250 is:  ú
ASCII  251 is:  û
ASCII  252 is:  ü
ASCII  253 is:  ý
ASCII  254 is:  þ
ASCII  255 is:  ÿ

We might want to use some of these characters in Liberty BASIC, and it adds a nice, professional appearance to our programs when we do so. We've been discussing copyright issues in the group recently. Let's place a copyright notice in an ABOUT box in our open source editor:

menu #1, "&Help",_
    "&Liberty BASIC Help",[help],_
    "LB &Tutorial",[tutorial],_
    "&About",[about]

We'll use a NOTICE message for our ABOUT box. Let's give it a titlebar text of "About this editor..." We could indicate a copyright like this:

	copyright The Liberty BASIC Community

or like this:

	(c) The Liberty BASIC Community

We can place the copyright character - chr$(169) - in our message so that it looks like this:

	© The Liberty BASIC Community

Here is our ABOUT routine:

'** NEW **
[about]
    message$="About this editor..."+chr$(13)+_
        chr$(169)+"The Liberty BASIC Community"
    notice message$
    goto [loop]


The entire code for the new version of the open source editor is attached to this newsletter: "open07.bas"

Several people have published code using some of the routines we have placed into this open source editor. This is so encouraging! Some people have shared their own programs with me privately. I'd like to urge people to publish these so that all can marvel, and learn. I have certainly been enjoying the programs that people share with me!


Newsletter compiled and edited by: Brosco and Alyce. Comments, requests or corrections: Hit 'REPLY' now! mailto:brosc-@orac.net.au or mailto:awatso-@wctc.net