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 #72 - MAY 2000

© 2000, Side by Side Software

http://alyce.50megs.com/sss/

All Rights Reserved


In this issue:

  1. Making professional-looking applications
  2. Using spreadsheets
  3. Apology

In future issues:


NOTE

We try to present a variety of articles to satisfy as many different areas of interest, and as many levels of programming skill as possible. If a particular newsletter does not appeal to you, please be patient. Ideas for newsletter topics are always welcome, as are submissions of articles. Thanks.


"You may be disappointed if you fail, but you are doomed if you don't try."

- Beverly Sills
1- MAKING PROFESSIONAL-LOOKING APPLICATIONS

Sometimes, the difference between a professional-looking application, and one that looks amateurish is subtle. Here are some suggestions. Feel free to add to the list! Look at the professional programs on your own pc. Pay attention to the way they look and function, and try to emulate them as much as possible. If you plan a departure from the norm, do it for a reason. Most of us prefer to use things that function in the way that we expect. When we get into a strange car, we know to look for the ignition on (or very close to) the steering column. An automaker would not be praised for designing a car that hid the ignition in the glove box!

Suggestions:

1. Do not use windows that cover the entire screen unless there is a really good reason to do so. It is especially important to avoid covering the Win95-98 taskbar. If you really feel that your application needs to be full screen, consider using the ShowWindow api call with the flag

_SW_SHOWMAXIMIZED.

 

open "user.dll" for dll as #user 'open user dll

h=HWND(#main) 'your window's handle

calldll #user, "ShowWindow",_ 'the api function

h as word,_ 'your window's handle

_SW_SHOWMAXIMIZED as ushort,_ 'flag to maximize the window

result As word

close #user 'close the dll

 

 

2. Do not use a graphics window, unless it is necessary to your application. Also, do not use scroll bars in a graphics window unless there will be a need for the user to scroll graphics.

3. Use "hot keys" for all menu titles and items. Place an amersand, "&" in front of the letter that will function as the hot key. When the user presses ALT plus that letter, the menu item will be activated. Don'trepeat a hot key letter within a menu. Here is the way to add hot keys to a file menu. If the user presses ALT - F - X, the application will close:

menu #1 "&File","&Open",[open],|,"E&xit",[exit]

Have a look at the programs on your system, and try to use the same hot keys as they do. Some of these are standard. The ALT - F - X combination is one of these standards.

 

4. Locate the EDIT menu on the menu bar if you have a texteditor control. The EDIT menu is automatic. If you do not give it a place, it will be placed by your program. It looks better to have the EDIT menu follow the FILE menu, as it does in most programs. Since Liberty BASIC controls the items in the EDIT menu for a texteditor, you need only list its name to place it.

menu #1 "&File","&Open",[open],|,"E&xit",[exit]
menu #1 "&Edit"
menu #1 "&Help","&Topics",[help],|,"&About",[about]

 

5. Use the FONT command for controls. Most controls will display the font of your choice, when given a FONT command. Choosing Arial, or Times New Roman will look better than the default system font. Don't forget to place underscores in the font name if it contains blank spaces. Be sure to include the "!" in front of the font command to controls like buttons that can accept a new text string. Example:

print #1.button1, "!font times_new_roman 0 16"

You can count on the user having these fonts:

arial
courier new
times new roman

They will also have the bold, italic, and bold italic versions of the three styles.

arial
arial bold
arial italic
arial bold italic
&etc.

6. Line up numbers with USING. This works when printing to the main window, and to controls. It is also important to used a fixed-width font with USING. Courier New is the fixed-width font that will be on all systems, so it is a good choice. The little example here shows a texteditor, statictext, button and main window displaying text that has been formatted with USING.

statictext #1.1, "",10,10,200,26
statictext #1.2, "",10,40,200,26
texteditor #1.3, 10,70,200,100
button #1.4, "",[quit],UL,10,180,200,30
 
open "Line it up" for window as #1
print #1, "trapclose [quit]"
 
'change font in controls:
print #1.1, "!font courier_new 0 20"
print #1.2, "!font courier_new 0 20"
print #1.3, "!font courier_new 0 20"
print #1.4, "!font courier_new 0 20"
 
number1$=USING("######.##",12345.67)
number2$=USING("######.##",123.45)
 
'print in statictext controls:
print #1.1, number1$
print #1.2, number2$ 
 
'print in texteditor:
print #1.3, number1$
print #1.3, number2$ 
 
'print in button:
print #1.4, number2$
 
'print in main window:
print number1$
print number2$ 
 
input a$
 
[quit]
close #1:end
 

7. Keep things in line, and size them accordingly. Place buttons and other controls in rows and columns. Try to leave equal borders all around controls. Don't have controls clustered on one side of a window, leaving a lot of blank space on the other side. Keep sizes small, but not tiny.

Always give buttons a size. If you do not, Liberty BASIC will determine the size, based upon the text the button contains. The size of the button then remains constant, so a font command that specifies a larger font size will cause the button caption to disappear off of both sides of the buttons. Try this little example to see. The top button has been given a size large enough to accomodate the caption when written in a larger font. The bottom button has not been given a size by the programmer.

button #1.1, "Correct",[quit],UL,10,10,120,40
button #1.2, "Not Correct",[quit],UL,10,50
open "button example" for window as #1
print #1, "trapclose [quit]"
 
'change font in controls:
print #1.1, "!font arial_bold 0 30"
print #1.2, "!font arial_bold 0 30"
 
input a$
 
[quit]
close #1:end

 

8. Use good bmpbuttons. If you are laughing up your sleeve right now, feel free to laugh out loud. My son teases me constantly about my bmpbuttons. I'm no artist. When I want to make sure to have professional-looking bmpbuttons, I use images that somebody else has drawn.

Carl Gundel has provided us with a nice set for starters. I like to "borrow" buttons from applications on my system. Use the "print screen" key, then PASTE into your paint program, crop and save as bmp. If you are using LB 1.4x, make sure the bmps are formatted to 256 or fewer colors. In LB2, you do not have that restriction, but keep in mind that 24-bit bmps are much larger files, and most buttons do not require more than 256 colors. Choose the SAVE AS feature in your paint program, and save as 256 (or 8-bit) bmp.

There is a nice set of button templates available for download at the Liberty BASIC Network:

http://liberty-basic.com/resources/tools4lb/bmpbtns.html

 

9. Avoid using too many NOTICE messages. They can get annoying. If you need to convey several bits of information, or get more than one bit of input from a user, build your own dialog window. Make it easy with a gui-builder. FreeForm ships with Liberty BASIC, and it makes a great starting place. You might also want to try Enhancer Pro, which is available here:

http://liberty-basic.com/resources/enhancer_pro_center/epro.html

Dialog windows are good for user input because the user can tab from one field to the next. The order of tabbing is the same order as the commands to list the controls, not the order in which they appear on the window.

The exception is that in the LB1.4x, buttons are added in a group by LB, no matter the order you have listed the controls. Keep this in mind. If you designate a button with the extension "default" it will be activated automatically when the user hits ENTER. Example:

button #main.default, "OK",[ok],UL,200,150,80,26
open "Get Input" for dialog as #main

10. Don't leave the user guessing. A blank combobox does not look good. Fill the box with a selection. You can do this by selecting the string to display, or by selecting the index of the item to display. Let us assume that the array item at index(1) is called "hello". Either of these commands would cause "hello" to be displayed in the combobox:

  print #handle.ext, "select hello"
  print #handle.ext, "selectindex 1"

Don't forget that variables must be placed outside of the double quote marks. If the index and string are variables, do it like this:

  num=1
  item$="hello"
 
  print #handle.ext, "select ";item$
  print #handle.ext, "selectindex ";num
 

11. Don't get carried away! One former LBer once confided to me that fully half the lines of code in his programs was for the gui. This is a personal opinion, and many may not agree, but this seems excessive to me.

Comments?


2- USING SPREADSHEETS

As of this writing, Liberty BASIC 2.0 does not contain spreadsheet window capabilities. Use LB 1.4x to run the examples provided.

 

SPREADSHEET WINDOWS

Spreadsheet windows are very specialized tools. They are ideal for data handling and manipulation, and are actually quite versatile. Although they are not set up to import and interpret data from other spreadsheet/database applications, they do allow you to save and load data in specially formatted files.

The spreadsheet used in Liberty BASIC is composed of 35 rows of 26 columns labeled from A to Z. The upper-left-most cell is A1 and the lower-right-most cell is Z35. As an example of the layout, cells used for an application might be set up as follows, with 7 columns, and 3 rows:

 

A1	B1	C1	D1	E1	F1	G1
 
A2	B2	C2	D2	E2	F2	G2
 
A3	B3	C3	D3	E3	F3	G3

A spreadsheet window contains a menubar, with an automatic EDIT menu. You cannot add other menus to a spreadsheet window, or remove the EDIT menu.

Since you may not access your own menus for user choices, you might need to add buttons to the window. For an example, look at the program grapher1.bas that comes as part of the Liberty BASIC distribution package.

The program and its associated data file are attached to this newsletter.

The buttons used are bmpbuttons, accessing LOAD, SAVE, and the graphing function provided in this application. Regular buttons will work also.

IMPORTANT! Button commands must designate buttons WITHOUT extensions. A button command that includes an extension will not be understood by the spreadsheet window, so the button will not be displayed:

bmpbutton #sheet, "bmp\grphbttn.bmp", [graph], LR, -17, -15      'CORRECT
bmpbutton #sheet.b, "bmp\grphbttn.bmp", [graph], LR, -17, -15    'WRONG!!!

 

You may not use other controls in a spreadsheet window. It will not accept textboxes, listboxes, comboboxes, groupboxes, or graphicboxes. Statictext controls are not allowed, but you may display text on the window by printing it to a cell. Printing text strings on a spreadsheet window will be discussed in more detail later, but we'll give an example here. The text "Title for the graph:" was printed with the command:

Print #sheet, "cell A15 'Title for the graph:"

Under the menu bar of a spreadsheet window, you will find a text field box. All user keyboard activity is entered into this box. A user types the data that he wants to enter for the cell that is currently highlighted. When he wants to place the data from the text box into the highlighted cell, he presses ENTER. The user may navigate around the cells to select a cell for data entry by clicking on the desired cell with the mouse, or by using the keyboard arrow keys.

Each cell can contain one of three types of data: string, number, or formula. If a user enters text into a cell that is formatted for numbers, the value will be 0. A user may enter arithmetic expressions into cells formatted for number or formula. If the user types 7+4 into the text box, then presses RETURN, the selected field will contain the number 11. Cells are 11 spaces wide. A number with more than 11 digits will not display properly, but text will run into the cells to the right.

You may place a text string into a cell by printing to it and preceding the text string with an apostrophe, or single quote character:

Print #sheet, "cell A1 'Name       Price      Quantity"

You may place a number into a cell by printing its value. It can be an integer, or a number with decimal places (a floating point.)

Print #sheet, "cell C12 458"    	'the cell will display  458

A formula is a simple arithmetic expression, using numbers or cell references. If cell references, such as B3 are used, the current numeric value held in that cell will be used in the calculation. The result of the formula is displayed in the cell's position. The usual precedence is ignored, so any formula is always evaluated from left to right and parenthesis are not permitted, nor are they needed. A formula to compute the average of 3 cells might be:

Print #sheet, "cell A5   A1 +  A2 + A3  /  3"

If you print a formula to a cell, the value displayed in the cell will change every time any of the referenced cells is changed. In the above example, any time the user changes a value in A1, A2 or A3, the updated average will be displayed in cell A7.

MODES

The spreadsheet has two modes, manual and indirect. Manual mode is the default mode, and it means that the user can move about from cell to cell with the arrow keys, with all cells being accessable. In manual mode, the user decides which type of data is to be entered into a cell: number, string, or formula. If a user enters a formula into a cell, the formula will be printed in the upper text box any time that cell is highlighted.

print #sheet, "manual"  		'sets the window to manual mode

If a window is set for indirect mode, the user can only move to cells predefined by the controlling application, which also decides what type of data is contained by each cell, either string or number.

print #sheet, "indirect"		'sets the window to indirect mode

When contents are "justified" this means that they are lined up to one side of the cell or the other. You may format a column to be right justified, with the "format COLUMN right" command. The default format is justified left, but should you need to reset the justification to "left" in your program, call the "format COLUMN left" command. For columns that will contain monetary amounts, use the "format COLUMN fixed" command. It causes numbers in the column to be justified right, and to assume 2 decimal places. This one is REALLY handy! BEWARE! If you use a "fixed" format, numbers are truncated to two decimal places, they are NOT rounded, so you may lose precision. Examples:

Print #sheet, "format A left"    'justifies contents to left side of cells in column A
Print #sheet, "format C right"   'justifies contents to right side of cells in column C
Print #sheet, "format D fixed"   'justifies column D cells right and assumes 2 decimal places

In indirect mode, you must specify which cells a user may access, and which type of data they may contain with the "user ADDRESS string|number" command. Examples:

Print #sheet, "user A2 string"	'allows user to access cell A2 and enter strings
Print #sheet, "user B4 number"	'allows user to access cell B4 and enter numbers

A cell is highlighted when a user navigates to it with the arrow keys, or clicks it with the mouse. The programmer can highlight a cell with the "select ADDRESS" command. Be sure to place the selector over the first cell that the user will edit. Example:

Print #sheet, "select E2"		'highlights cell E2

You may retrieve the contents of a cell with the "result? ADDRESS" command. You must follow this command with "input #handle, var$" of "input #handle, var" command. If there is no content, an empty string "" will be returned.

Examples:

Print #sheet, "result? A2"	'request contents of cell A2
Input #sheet, var$		'string contents are now in var$
 
Print #sheet, "result? B7"	'request contents of cell B7
Input #sheet, var			'numeric value is now in var

To answer the formula contained in a cell, use the "formula? ADDRESS" command. It must also be followed with "input #handle, var$", which will always return a string. Example:

Print #sheet, "formula? C5"	'gets the results of formula in cell C5
Input #sheet, var$		'string result is now in var$

To force the spreadsheet to display the current results:

Print #sheet, "flush"

You may load a Liberty BASIC spreadsheet file with the "load pathFileName" command. It will always have the extension ".abc" You must be sure to have the path and filename. If a filedialog is used, the correct path and filename are returned for use with this command. Loading a spreadsheet file will cause the data in the spreadsheet window to be replaced with the data in the loaded file. You may save a Liberty BASIC spreadsheet in a similar way with the "save pathFileName" command. Examples of both:

Print #sheet, "load c:\data\money.abc"	'loads the designated spreadsheet file
Print #sheet, "save c:\FEB\budget.abc"	'saves current data in designated file

It is a good idea to check to see if data is modified before allowing a user to close the program. Do it with the "modified?" command, followed by "input #handle, VarName$" to retrieve the contents. VarName$ will contain either "true" if the contents have been changed, or "false" if they have not been changed.

Example:

Print #sheet, "modified?"	'determine if data has been modified
Input #sheet, varName$		'varName$ will contain 'true' or 'false'

The default spreadsheet window does not display labels for the rows and columns. To restore the default, use the "nolabels" command. To display labels for rows and columns, use the "labels" command. Examples:

Print #sheet, "labels"		'displays row and column labels
Print #sheet, "nolabels"	'stops display of row and column labels

As with windows of type-window and -dialog, you may trap the close event that occurs when a user clicks the system close button on the titlebar of a window. Use the "trapclose branchLabel" command like this:

Print #sheet, "trapclose [exit]"	'sends program to [exit] upon system close event

 

A SAMPLE SPREADSHEET PROGRAM

The following tiny program demonstrates some of the spreadsheet functions. Try entering values into the cells -- a name for the item, then a price.

Hitting RETURN after entering the PRICE causes the tax and total to be calculated and displayed.

 

nomainwin                             'turn off mainwindow
WindowWidth=250 : WindowHeight=240    'set window dimensions
open "Sales Tax" for spreadsheet as #1'open the window
 
print #1, "trapclose [quit]"   'trap close event
print #1, "indirect"           'limit user access of cells
print #1, "cell A1 'Sales Tax Calculation"'place string into cell A1
print #1, "cell A3 'Item:"     'place string into cell A3
print #1, "cell A5 'Price: $"  'place string into cell A5
 
print #1, "cell A7 'Tax:   $"  'place string into cell A7
print #1, "cell A9 'Total: $"  'place string into cell A9
print #1, "format B fixed"     'format numbers to 2 decimal places
print #1, "user B5 number"     'format user cell B5=number
print #1, "user B3 string"     'format user cell B3=string
print #1, "select B3"          'highlight cell B3
print #1, "cell B7 B5*.05"     'formula to calculate tax
print #1, "cell B9 B7+B5"      'total=item price plus tax
print #1, "flush"              'show the spreadsheet
 
[loop]'input loop
input a$                       'input statement
 
[quit] 'closing routine
close #1 : end                 'close window and end
 


3- APOLOGY

This newsletter and Side by Side Software were begun by Brosco, and were part of his Liberty BASIC website. Shortly after joining the Liberty BASIC community, this clever and helpful person struck up a friendship with a relative newbie -- me. It was also at his instigation that I started my own website, Alyce's Restaurant. We discovered that we worked together very well, which brought about Side by Side Software. Brosco enlisted my help from the start with the Liberty BASIC Newsletter. He wanted a proofreader, but I did little more than add the occassional comma -- probably in the wrong spot! Brosco's life took a sudden turn in an unexpected direction a year ago. Yes, he's been gone a year now. He did keep in touch for a while, but I have not heard from him now for months.

People frequently ask me when he will be back. At this point, I would not count on his return. I took over as a temporary substitute with the newsletters and SSS. It has turned into a permanent position. I apologize to everyone who misses Brosco's expertise and his bright and energetic personality. I also miss him. Thanks for your immense patience with me.

Brosco generously paid his ISP bill, so that he could maintain his website even though he was unable to go online. He did this for a year, but his site now no longer exists. I've put many of his files online here:

http://www2.50megs.com/alyce/brosco/brosco.htm

Carl Gundel, the author of Liberty BASIC became a co-manager of this eGroup quite a while ago. Dean Hodgson has always been a major contributor to Side by Side Software, so putting his name on the website is long overdue.

Dean's help is invaluable and much appreciated. Thank you Carl and Dean.

Peace,

Alyce


Side by Side Software offers a Book for Liberty BASIC,

which is available in electronic form on a CDROM.

For details: http://alyce.50megs.com/sss/cd.htm


Comments, requests or corrections: Hit 'REPLY' now!

Dean Hodgson -- mailto:Hodgson.Dean@saugov.sa.gov.au

Alyce Watson -- mailto:awatson@wctc.net