PDA

View Full Version : Addressbook



fravado
07-04-2008, 18:25
Hi Petr, Eros.
Here a small program i ones wrote in the 90ties on Amiga with AmigaBasic, mayby someone can still use it for i do not have my Amiga anymore (pity)
Now what i want to do with this small program (which is a addressbook) is to use it in Tbasic. My question now is: "Is it possible ?" it still works with "DATA" which you have to fill in when you add a new name/address.... here it comes:

aa=1 (every time you add a new name, change the number)
DIM name$(aa), address$(aa), city$(aa), tel$(aa), remark$(aa)
start: CLS: PRINT
LOCATE 4,35: PRINT " ADDRESSES ": PRINT: PRINT
INPUT " WHO ARE YOU LOOKING FOR "; S$: CLS
FOR X = 1 TO aa
READ name$(x), address$(x), city$(x), tel$(x), remark$(x)
IF LEFT$(remark$(x), LEN(s$)) = s$ OR LEFT$(name$(x), LEN(s$)) = s$ THEN

PRINT (PRINT stands for empty line, but i guess you know that)

PRINT "Name : " ; UCASE$ (name$(x))
PRINT "Address :" ; address$(x)
PRINT "City :" ; city$(x)
PRINT "Tel :" ; tel$(x)
END IF
NEXT x

PRINT

LOCATE 22,2: PRINT "Use any key"
wait: (wait = a variable)
IF INKEY$ = "" THEN GOTO wait
RUN

So this is the program (also works with QBasic)
At the end of the program you write you data like:

DATA "petr","street*number","city or province","tel number"," & remarks if any"
---------------------------------------------------------------------------

so now aa becomes 1
the more DATA, the higher the number at the begin of the program becoms (aa)

you see this is a very old method and you still have to write your own DATA,
because i still donīt know how to programm a "DIRECT INPUT"
but i like this Addressbook and it works the way i want it to work.
Petr, i hope you can covert this into TBasic (?)

Hope that AMIGA / QBasic users have some use for it.
bye,
Frank.

Petr Schreiber
07-04-2008, 20:03
Hi Frank,

I have the thinBASIC code converted right in front of me ... but I will not put it here, as it would not be ... educative :)

Instead I can guide you to the final script in steps, during which you will learn something about thinBASIC.
The conversion will go in 2 phases:

first will be almost 1:1 conversion
second will load data from external file, eliminating need for manually setting AA variable.


So step one, which will be the most "painful".
Although it might look odd, or too "wordy", you will see on the end it was a good idea ;)

You could store the data in separate arrays as usual, but to keep the information record homogeneous, we will keep it in one special variable.

We have a various kind of information: name, address, city, telephone and remark.
So we will create UDT - user defined type, like this:



TYPE TContact
cName as string * 16
cAddress as string * 32
cCity as string * 32
cTel as string * 32
cRemark as string * 64
END TYPE


As you can see, I have limited for example the name to be 16 characters long, by using "* 16".
But this TYPE is nothing, just a construction design. To create variable of this type, you can use the DIM keyword.

As we want to have multiple persons, it will be array of TContacts:


DIM Persons(3) AS TContact

DIM NumPersons AS INTEGER
NumPersons = UBOUND(Persons)

... this will create space for 3 persons. DIM keyword serves to create variable, AS something determines type of variable. TContact is our custom type to hold info about people, INTEGER is datatype to hold "whole" number, without the fractional part.

NumPersons will have the same function as "aa" in your program, but it just has more clear name :)

The last line will put the number of persons to variable NumPersons. Why? UBOUND means something like "how many elements the array has". So UBOUND(Persons) means "tell me how big the Persons array is".

To fill the data in for person 1, you can use this notation:


Persons(1).cName = "Frank"
Persons(1).cAddress = "Mysterious Land"
Persons(1).cCity = "Mysterious City"
Persons(1).cTel = "123"
Persons(1).cRemark = "thinBASIC user"


Now comes your part - as a ... sounds silly ... but ... as a homework, fill the persons 2 and 3 with unique data like I did with person 1, and then print their data into the console. If you will succeed in this, the rest will be piece of cake.

Are you ready for this learning challenge :) ?


Petr

fravado
08-04-2008, 14:04
Hi Petr.
I am not sure if i understand what you mean with:

"fill the persons 2 and 3 with unique data like I did with person 1, ((and then print their data into the console.)) If you will succeed in this, the rest will be piece of cake.

The part between doble brackets is the one i do not fully understand.
Further, do you mean to write it the same as you did ? like a copy ? ok, iīll try to do it the way you told me. But i nead some explanation on my first question the (( )) one.
Thanks for your help, i hope it works.
P/S i think you made a small mistake in your code.... When running, it gives Error code 18 "unknown command" i think it is the letter 's' in Persons, but then again i could be wrong, of which i am sure i am.
Bye Frank.

Petr Schreiber
08-04-2008, 15:35
Hi Frank,

you are right, there was a typo in the sample, of course Person should be Persons :-[

In the (( )) part I just wanted you to try to print the data from variables ( for example ALL person names ) to the console window ( that thing you used PRINT to put text into on Amiga ).
So in console would be:


Frank
John
Bill

( in case you choose John as name for 2nd and Bill for 3rd person )
One requirement more, use the FOR statement to help print the text.

Little hint - to make the console not disappear after printing the text, use CONSOLE_WaitKey.

Here is a code "skeleton" for your ... homework :):


USES "Console"

TYPE TContact
cName as string * 16
cAddress as string * 32
cCity as string * 32
cTel as string * 32
cRemark as string * 64
END TYPE

DIM Persons(3) AS TContact

DIM NumPersons AS INTEGER
NumPersons = UBOUND(Persons)

' -- Data filled for person #1
Persons(1).cName = "Frank"
Persons(1).cAddress = "Mysterious Land"
Persons(1).cCity = "Mysterious City"
Persons(1).cTel = "123"
Persons(1).cRemark = "thinBASIC user"

' < add here data filled for person #2 >

' < add here data filled for person #3 >

' < add here some code to print names of all the 3 persons >

CONSOLE_WaitKey



Bye,
Petr