Basic BASIC

Heard the one about the man and his keyboard?
Paul Jones reveals all...

Fields of glory

Last issue I mentioned the default edit field with our Register PDO dialog. This was passed in the function:

Where regcode is the name of the edit field we're interested in - it's the place for editing the registration code.

When this line is executed, the dialog is displayed with an editable text field following Code:
where you can enter text - give it a try.
The [Esc] key can be used to clear the field.

This section of the program displays the dialog box, allowing the user to enter a key then press REGISTER!
We then check what the user typed and compare it with the real key in our program code.
The moment the user presses the REGISTER button, we can display a confirmation alert box informing the
user whether the key they entered is correct or incorrect.
 

CASE reg:
  butn=FNdialog (regist, regcode)
  IF butn=regbut THEN
    SelectTree regist
    txt$=FNgette_ptext$ (regcode)
    IF txt$="ReGiStEr" THEN
      junk=FNform_alert (1,"[1][ Key correct! ][ OK ]"
    ELSE
      junk=FNform_alert (1,"[1][ Incorrect key! ][ OK ]"
    END IF
  END IF
 

Here's an explanation. The FNdialog function displays the dialog and waits for user input. The button pressed is returned in butn. If the button pressed is the register button (named regbut) then we need to find out what the user typed as the registration code. We do this using a function called gette_ptext$, which takes the object as the parameter. First we have to say which dialog we were looking at and this is where the SelectTree call comes in. I'll include a more detailed explanation of SelectTree in a future article. Remember to add extra STATICs to declare any variables HBASIC doesn't recognise.

We'll take a closer look at text input checking next issue - the "Look out hackers!" boxout offers an few clues to the topics we'll be covering.

Stop the press

The following routine can output an entire file to the printer. First it opens a file called MYTEXT.TXT to read and gives it a handle (name).
 

CASE prin:
  OPEN "MYTEXT.TXT" FOR INPUT AS #1
  REPEAT
    LINE INPUT #1,a$
    LPRINT a$
  LOOP UNTIL EOF (1)
  CLOSE #1
 

There's an example MYTEXT.TXT file on the Reader Disk but any ASCII format file will work so long as it's placed in the same directory as the program executable. We then repeat the following steps:

until there's no more data to output or the "End Of File" (EOF) marker is reached. After all the data has been sent to the printer, the file is closed.
 

Shareware delays

Last issue we talked about the theory of shareware delays/progress bars and you'll find some commented examples on the Reader Disk.
 

Hacker alert!

When you select the compile option, your source code is converted into machine code which your TOS computer can execute directly from the desktop. This means the source code no longer has to be loaded and run from within HBASIC.

However, strings remain visible in the source code, for example:

IF txt$="ReGiStEr" THEN...

can be read using any disk editor which is an open invitation to any hackers trawling through your source code. The solution is to encrypt passwords or other sensitive data and next issue we'll take a closer look at string manipulation.

Here's a section of compiled code loaded into a disk editor, notice the characters "ReGiStEr" are clearly visible in the right hand section surrounded by anonymous code - easy prey for hackers!
 
 

HiSoft BASIC Useful Routines & Documentation Guide

A specialist Reader Disk, compiled by Paul Jones, to accompany these tutorials is available. The disk includes:
 
 

 
[Home] [Info] [Back] [Next]