View previous topic :: View next topic |
Author |
Message |
MadMax
Joined: 24 May 2005 Posts: 53 Location: Kingston, Ontario, Canada
|
Posted: Wed Jan 30, 2008 8:08 pm Post subject: Calling a subroutine inside a module? |
|
|
Hi All,
Is there any tricks / rules regarding creating a module which has subroutines within the module.
For instance, I want to create a module which will incorporate, declare and call subroutines from within the same module.
I've been able to get this to work with only one module that I've written, and not been able to get it to work again. I can't figure out what I did differently to make it work.
Any tips?
Best,
Chris |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Wed Jan 30, 2008 9:34 pm Post subject: |
|
|
Will work with one module, because you need to declare any subs/functions before any executable code. So the declarations at the top of that module will be ok, but then you cant add another module as well, since its declarations will come after the code in the first.
Just write the declarations in one block in your main code, after including all the modules you need. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
MadMax
Joined: 24 May 2005 Posts: 53 Location: Kingston, Ontario, Canada
|
Posted: Thu Jan 31, 2008 4:00 am Post subject: |
|
|
Thanks Adrian. I will give that a try tomorrow.
Chris |
|
Back to top |
|
|
MadMax
Joined: 24 May 2005 Posts: 53 Location: Kingston, Ontario, Canada
|
Posted: Thu Jan 31, 2008 6:25 pm Post subject: |
|
|
How does one call or use a module multiple times from within your main body of code.
Is it ok to use the $include statement for a module, multiple times within your main body of code?
I get compile errors when I do this.
Thanks,
Chris |
|
Back to top |
|
|
MadMax
Joined: 24 May 2005 Posts: 53 Location: Kingston, Ontario, Canada
|
Posted: Sat Feb 02, 2008 8:12 pm Post subject: |
|
|
Is this question regarding using a module multiple times within a body of code a silly question?
Is it poor programming?
You can tell me if it's just plain poor programming... I can take it... |
|
Back to top |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Sat Feb 02, 2008 9:53 pm Post subject: |
|
|
Assuming you are defining some subs/functions in the module, you only need to include the module once. Then you can call the subs/functions as many times as you want.
The $include statement simply places the module contents into your main bas file at compile time, so the result is just the same as if you had one huge bas file. _________________ If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.5 |
|
Back to top |
|
|
MadMax
Joined: 24 May 2005 Posts: 53 Location: Kingston, Ontario, Canada
|
Posted: Sat Feb 02, 2008 10:15 pm Post subject: |
|
|
Ok, I understand a little better now. I have been using this a little bit incorrectly.
So if I understand correctly now, I would want my module to essentially start as a subroutine.
So the module would be a collection of subroutines, without dangling code before or after the subs. Then I declare the subs in my main body of code, and those subs can be called from anywhere inside my main code.
I think I've got it! I'll give it a go!
Thank you.
Chris |
|
Back to top |
|
|
|