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

Brosco's Liberty Basic Resource Centre Newsletter - Issue #3 - May 1998

 
 

In this issue:

  1. New Sites and Postings
  2. Tips and Tricks


!!!!!! STOP PRESS !!!!!!
 

Garrett's LB4All site is down. Hopefully this is not for long - as he has the most comprehensive collection of LB programs, snippets, etc. Also, with this site, we have the lost the Message Board and the Chat Room. Also missing is the ability for LBers to post their latest programs and snippets. Until Garrett sorts out the problems, feel free to send my any postings that you have to me at: mailto:brosco@orac.net.au - I will post them at my site, and then pass them over to Garrett when he's on the air again.

Along with Garrett's site, Tom Record and I had pages on his server. I have moved to http://users.orac.net.au/~brosco - hopefully my last move for a while. I havent heard from Tom, so I don't know if he's relocated yet - but this is another big loss. Tom has the best collection of DLLs that can be accessed by Liberty Basic.

Garrett, we wish you a speedy recovery from your "Website Deficiency Syndrome".


1)New Sites and Postings

Tom and Alyce Watson have had to move from Crosswinds because of poor performance of the site. All of their Graphics and Games programs and tutorials can be found at:

Clocker's Computer Programs 
 
          http://www.wctc.net/~awatson/liberty.html

And since this is my newsletter, and can express MY opinions: Clocker has the best graphics programs available in the LB community. If you want to learn about Graphics programming - this site is a MUST!!!! Without the help Ireceived from Alyce, there would not be a single graphic posting at my site!

In my move from Crosswinds I am slowly updating my postings. My latest include an update of my VB to LB API converter, that has some bug fixes, an option to output directly to a file and improved call translation.

I have also posted a reusable subroutine to allow displaying of text in any orientation - around a circle, at an angle, etc. You can visit my site at:

Brosco's Liberty Basic Resource Centre

 
          http://www.orac.net.au/~brosco


2)Tips and Tricks.

 
Tip #1 - Continuation Lines

I find it extremely difficult to debug programs when lines of code dissappear off the right of the display. To overcome this, I break the line up into smaller sections that will fit in the display area. To do this, you must also inform LB that the code is Continued on the next line. Here's an example (taken from Issue #2):

    RandomN.Seed = RandomN.SeedTmp - _
            int( RandomN.SeedTmp / RandomN.C3 ) * RandomN.C3
 

The underscore character ( _ ) is used to indicate to LB that the line is continued. I have posted this because it is not well know to newer LBers, and I have had several questions regarding the meaning of the _.

This technique is also extremely useful when posting code to the message board, or sending it in an email - the Undescore allows you to reduce the length of the line of code and prevent an Email Reader from puting WordWraps in the middle of your lines of code.

 
Tip #2 - STATICTEXT

If you have ever written a Dialog Window, then I feel confident that you have used the STATICTEXT Control to put a text label on some input field, but did you also know that you can use the StaticText control to keep the user informed of progress of the current operation? Here's a small program that demonstrates some of the capabilities of STATICTEXT.

    nomainwin
    WindowWidth = 640
    WindowHeight = 480
 
    StaticText #w.st, "", 10, 10, 250, 50       ' *** NOTE 1
 
    open "Demo StaticText" for Dialog as #w
    print #w, "trapclose [close.w]"
 
    print #w.st, "Show line 1 of StaticText"    ' *** NOTE 2
    Notice "Line 1 should now be displayed."
 
    print #w.st, "Show line 2 of StaticText"    ' *** NOTE 3
    Notice "Line 2 should now be displayed."
 
                                                ' *** NOTE 4
    print #w.st, "Show line 3 of StaticText and use Auto wordwrap."
    Notice "Line 3 should now be displayed with automatic wordwrap."
 
                                                ' *** NOTE 5
    CrLf$ = chr$(13) + chr$(10)
    print #w.st, "Show line 4 of StaticText" + CrLf$ + _
            "With more text on the second line"
    Notice "Line 4 should now be displayed with text on the second line"
 
[loop]
    input var$
    goto [loop]
[close.w]
    close #w
    end 
 
*** NOTE 1:

In this case I have defined the StaticText control to have a value of "". You could give it an initial value if you want - the rest of the program will still work. Also note that I have given it a Height of 50 pixels, this allows a few lines of text to be displayed in the control. (I could make it more if I needed to).

*** NOTE 2

To get something displayed in the StaticText control, you simply PRINT to it.

*** NOTE 3

When I print to it again, the contents are overwritten with the new value.

*** NOTE 4

When I print a line that is too large for the width of the Control, it automatically wordwraps - and providing the Height of the control is sufficient, you will see the extra text on the next line.

*** NOTE 5

If you would prefer to decide where the WordWrap should take place, you need to insert a 'Carriage Return' and a 'Line Feed' - that is:

Chr$(13) + Chr$(10).

And just as an extra NOTE, I didnt read this in any manual, or see it in another program - I found this by experimenting! Don't be afraid to try out your ideas - you won't break anything!

 
Tip #3 - Debugging

Do you ever run your new program and get a weird error message like:

"Truncated not understood by ?" and Liberty Basic doesnt bother to inform you of the line that caused the error? Finding this type of error is easy. Simply Compile your program for 'Debug' mode and when the 'Trace Window' appears - Click on 'WALK'. When the program gets to the line in error, the line will be highlighted in the Trace Window.

Tip #4 - Disappearing Programs 

Have you ever saved a new program that you've been writing - and then when you come back to do some more coding - its nowhere to be found?

Chances are, that when you saved it, you didn't put the '.BAS' extension on the file name, and LB doesn't add it for you. So if you saved 'myprog', the LB Open file Dialog wont find it, because it only searches for files with an extension of ".BAS". Try expanding the File Dialog search by clicking on "All Files".

Tip #5 - VSTUB Errors and DLL Call Errors.

These regularly occur when you start using API calls in your program. Usually a VSTUB error is caused when you specify the incorrect number of parameters in the call or when you have specified incorrect types - WORD instead of LONG, or PTR instead of Word, etc.

Another reason is when the API is returning a value in a string$. You must ensure that string$ has been set up with sufficient length to hold the value being returned:

 
    string$ = space$(256) + chr$(0)
 

The Space$(256) fills string$ with 256 blanks (sufficient for most calls) and the Chr$(0) informs LB that the value of string$ will be updated by the function.

After you have fixed this, the next error you will get is the 'Dynamic Link Library Call error'. This one is a bit more obscure, but here's some of the mistakes that I have made to cause this:

filename as PTR, _

In this example 'filename' is a number, NOT a string as expected, and should be coded as:

    filename$ as PTR, _

Another example is when you are passing a WORD:

    xPos as word, _

if xPos was calculated by your program, it possibly doesnt have a nice INTEGER value, so what you need to do is:

    xPos = int(xPos)
    ....
    xPos as word, _ 

Also, if the parameter needs to hold a negative value, say:

    angle = -45
    .....
    angle as word, _

will also cause the error. What you must code is:

    angle = 45
    angle = hexdec("&H10000") - angle
    .....
    angle as word, _
 
Tip #6 - Arrays
 

People new to programming are often confused by arrays, particularly two-dimensional arrays. Here's an example to help explain. Suppose that I was programming a game using a normal deck of playing cards. I could represent the values in the cards like this:

dim cards$(13)
    cards$(1) = "Ace"
    cards$(2) = "Two"
    ....
    cards$(10) = "Ten"
    cards$(11) = "Jack"
    cards$(12) = "Queen"
    cards$(13) = "King"
 

But now, to represent the suites - hearts, diamonds, clubs and spades, I change the array to:

    dim cards$(13, 4)
 

and thus:

    cards$(1,1) = "Ace of Hearts"
    cards$(1,2) = "Ace of Diamonds"
    cards$(1,3) = "Ace of Clubs"
    cards$(1,4) = "Ace of Spades"
    ....
    cards$(13,4) = "King of Spades" 
 

See, its all very easy really!


Newsletter written by: Brosco. Comments, requests or corrections to: brosco@orac.net.au Translated from Australian to English by an American: Alyce Watson. Thanks Alyce.

Actually, Alyce does much more than correct my grammar and spelling. She is constantly giving me suggestions, improvements, etc. I should change the nameto "Alyce and Brosco's Newsletter" - but Alyce prefers to stay in the background - and you know that I like to be noisy and draw attention to myself! So the name remains the same.