Spécial ! |
Version mobile de l'aldweb Site m.aldweb.com Ni Français, ni Anglais ?Essayez donc l'un de ces drapeaux :
|
|
Météo / Spam / www |
Météo Lyon
aldweb contre le SPAM
|
|
|
|
|
|
|
- Forum - iziBasic
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257
Sujet n° 1104 |
Creating a library of common subroutines |
le 15/02/2005 @ 17:33 par Karan
|
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 |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 1 -------- le 15/02/2005 @ 18:58 par Montalvo
visiteur |
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!
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 2 -------- le 15/02/2005 @ 21:09 par aldweb
visiteur |
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 |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 3 -------- le 15/02/2005 @ 22:57 par aldweb
visiteur |
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 |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 4 -------- le 15/02/2005 @ 22:59 par Montalvo
visiteur |
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 |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 5 -------- le 15/02/2005 @ 23:10 par aldweb
visiteur |
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 |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 6 -------- le 15/02/2005 @ 23:22 par Montalvo
visiteur |
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."...
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 7 -------- le 16/02/2005 @ 09:42 par Khertan
visiteur |
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. |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 8 -------- le 16/02/2005 @ 15:26 par Karan
visiteur |
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. |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 9 -------- le 17/02/2005 @ 23:32 par aldweb
visiteur |
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 |
|
|
sujet actif
sujet clos
Important!
Nouveau message -
Rectifier message
Clôturer sujet
Remonter
|
|
|
|
|
|