aldweb

Close I. aldweb

Close II. PC Freeware

Close III. Palm Freeware

Close IV. Palm Shareware

Close V. iziBasic Palm

Close VI. Palm Knowledge

Close VII. Pocket Computer

Close VIII. miniPortail

Special !



Mobile version of
the aldweb Site

m.aldweb.com


Neither French, nor English?

Try one of these flags then:
[de] [es] [it] [pt]
Search




Weather / Spam / www

Lyon Weather


aldweb against spam


Newsletter
To receive news about this website, consider subscribing to our Newsletter.
Subscribe
Unsubscribe
298 Subscribers
Family's web sites

Webmaster - Infos
Friends News
Visits

   visitors

   visitors online

Poll
What do you think of the new design of the aldweb Site?
 
Great !
Beautiful
Average
So ugly...
Results
forum.gifForum - iziBasic - Topic #1104

Forum - Forum
iziBasic - iziBasic


Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257

active  Topic # 1104  Creating a library of common subroutines

15/02/2005 @ 17:33
by Karan

Anonymous



While writing code in izibasic, I find that I am using certain sub-routines quite commonly in a many programs. Is it possible to compile a separate file containing all these commonly called sub-routines and attach this 'library' file to any new program I am writing. That way I can call the sub-routine (or function) when I want, without having to retype it each time
Write to Karan   Post an answer  Top

[]   


Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 1
--------
15/02/2005 @ 18:58
by Montalvo

Anonymous

visitor
I don't know if IZIBASIC can INCLUDE code from other files, but this is what I do:

1. Theres a program called SHORTCUT5. The description of this program, lets you have an idea of his potential:

..."ShortCut5 is a PalmOS 5.x preference panel which supports large (up to 4096 characters in size) shortcut definitions. The system shortcuts only supports small (about 45 characters in size) shortcut definitions. ShortCut5 shortcuts are in addition to the system shortcuts.

Limitations. Maximum of fifty shortcuts definitions. Each shortcut name is from one to four characters in length. Shortcut names are case sensitive and cannot contain the period "." character. ShortCut5 is only supported on PalmOS 5.x and on locales that use single byte characters. ShortCut5 will not recursively expand shortcut definitions."..

You can find it here:
http://www.palmgear.com/index.cfm?xyz=58307

2. Using SHORTCUT5, create one shorcut for every common routine that you use. I have one for center text, another one for dealing with dates, etc.

3. In PIAF (or your favorite Palm DOC editor) just type the shortcut that you need and the code is automatically inserted.

TIP: I have a shortcut to create a basic framework for new izibasic applications. It is called .izi, so everytime I start a new program in PIAF, I just type .izi and the following is inserted:


'programa.ibas
{creatorID "mcom"}
{parser on}
'{resourcefile + "nn-rsc"}
'{minosversion 3.5}

const x$­­="Creado por:"
const y$­­="MComm/TuPalMX"
const z$­­="Guadalajara, MEXICO"
aboutbox x$­­+y$­­+z$­­

begin

end


Try it. Works for me, maybe works fine too for others.

Greetings from Mexico!
Write to Montalvo   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 2
--------
15/02/2005 @ 21:09
by aldweb

Anonymous

visitor
Montalvo's way copies and pastes the source code of the routines each time they are needed. This is a very good trick. It just has one bad side effect: each time you upgrade one routine, you have to replace it in all source codes where you used it.

Another way, and I think that it is by far the best one is to use the CHAIN statement.
Build one secondary source code in which you will put all these routines with a jump table affected to one variable.

Quick and dirty example (not tested...):

Main source code:
A=2 : CHAIN "Routines.ibas"


Routines source code:
_Sub1:
...
RETURN

_Sub2:
...
RETURN

BEGIN
SELECT CASE A
CASE 1
GOSUB _Sub1
CASE 2
Gosub _Sub2
END SELECT
CHAIN "Main.ibas"
END



This is for the time being. I indeed should consider some include compiling directive. Thanks for the idea (and not thank you for the extra work!).

Cheers

@+
aldweb
Write to aldweb   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 3
--------
15/02/2005 @ 22:57
by aldweb

Anonymous

visitor
Montalvo,

ShortCut 5 is now in my device
This .izi shortcut is a great idea, it was my first shortcut in my ShortCut 5

So thank you very much for this great trick that you provided us here.

Cheers

@+
aldweb
Write to aldweb   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 4
--------
15/02/2005 @ 22:59
by Montalvo

Anonymous

visitor
Two comments... well, two and a problem:

1. ..."It just has one bad side effect: each time you upgrade one routine, you have to replace it in all source codes where you used it."...

What was USED was used.
No really, only on the ones that it should. When you update a routine, you update the shortcut and your NEXT programs will benefit from it (or a previous one if you decided to do that). As I say this is just a way to work, and one benefit of this forum is that we feed each others from "every head (and it's contents)".



2. ..."END SELECT
CHAIN "Main.ibas"
END


Just if ALL my programs are named "main.ibas". Did I miss something with this?

3. I vote for the INCLUDE statement.

4. I did a quick try of your method as follows:

'tuno.ibas
{creatorid "mCoi"}
begin
b$­­="**":c$­­="**"
a=2:chain "func.ibas"
gprint "Back to TUNO...",10,80
gprint b$­­,10,30
gprint c$­­,50,30
x=waitevent
end


And a "func.ibas" to include a small routine that modifies the variables values:

'func.ibas
{creatorid "mCoj"}
begin
gprint "Inside FUNC...",10,60
b=a*100
b$­­=str$­­(b,0)
c$­­="Hello"
chain "tuno.ibas"
end


The bad news is that it doesnt work as intended. The "Inside FUNC" label was displayed and the program FREEZES, and you will need a softreset to get back to life your palm.

The "Back to TUNO.." was never displayed, so I guess the returning point is lost after the CHAIN, and that is the reason of the FREEZE.

** Tested on Zire31 with izibasic 4.2
Write to Montalvo   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 5
--------
15/02/2005 @ 23:10
by aldweb

Anonymous

visitor
1) I agree

2) This is the side effect of my trick: You need to rename this "main.ibas" each time you apply this Resources.ibas to one program.

3) Me too!

4) The return point of a CHAIN is the BEGIN statement of the chained code segment. So your program just gets into a never ending loop.
So, do this:
'tuno.ibas
{creatorid "mCoi"}
begin
if a=0 then
b$­­="**":c$­­="**"
a=2:chain "func.ibas"
end if
gprint "Back to TUNO...",10,80
gprint b$­­,10,30
gprint c$­­,50,30
x=waitevent
end

That should work.

Cheers

@+
aldweb
Write to aldweb   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 6
--------
15/02/2005 @ 23:22
by Montalvo

Anonymous

visitor
Yeap, that works! Very well.
This is what I love of life (with a little help of internet): "Every day you learn something new!"

Thanks!

P.S. And we can add it on the manual ..."The return point of a CHAIN is the BEGIN statement of the chained code segment."...


Write to Montalvo   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 7
--------
16/02/2005 @ 09:42
by Khertan

Anonymous

visitor
Yes ... it s a lack in the manual ... but in all other basic calling a CHAIN result a return in the begin of the programm which do the chain call.
Write to Khertan   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 8
--------
16/02/2005 @ 15:26
by Karan

Anonymous

visitor
I know I should'nt be asking you this... Any way of getting user defined functions in a future release of izibasic? That should solve this problem.
Write to Karan   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 9
--------
17/02/2005 @ 23:32
by aldweb

Anonymous

visitor
User defined functions would bring added value if I was to think about implementing local variables.
Otherwise, a function would be nothing else but a clone of "GOSUB Label".

Cheers

@+
aldweb
Write to aldweb   Post an answer  Top
active topic active   closed topic closed   Sticky Sticky   New New message   -   Correct Correct message   Close Close topic   Make sticky Make sticky
[]
Forum Topic  Forum 



 
^ Top ^