Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Calling a subroutine inside a module?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
MadMax

Bascom Member



Joined: 24 May 2005
Posts: 53
Location: Kingston, Ontario, Canada

canada.gif
PostPosted: Wed Jan 30, 2008 8:08 pm    Post subject: Calling a subroutine inside a module? Reply with quote

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
View user's profile Visit poster's website MSN Messenger
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Wed Jan 30, 2008 9:34 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
MadMax

Bascom Member



Joined: 24 May 2005
Posts: 53
Location: Kingston, Ontario, Canada

canada.gif
PostPosted: Thu Jan 31, 2008 4:00 am    Post subject: Reply with quote

Thanks Adrian. I will give that a try tomorrow.

Chris
Back to top
View user's profile Visit poster's website MSN Messenger
MadMax

Bascom Member



Joined: 24 May 2005
Posts: 53
Location: Kingston, Ontario, Canada

canada.gif
PostPosted: Thu Jan 31, 2008 6:25 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website MSN Messenger
MadMax

Bascom Member



Joined: 24 May 2005
Posts: 53
Location: Kingston, Ontario, Canada

canada.gif
PostPosted: Sat Feb 02, 2008 8:12 pm    Post subject: Reply with quote

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... Shocked
Back to top
View user's profile Visit poster's website MSN Messenger
mattcro

Bascom Member



Joined: 03 Oct 2007
Posts: 327
Location: Scotland

uk.gif
PostPosted: Sat Feb 02, 2008 9:53 pm    Post subject: Reply with quote

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
View user's profile
MadMax

Bascom Member



Joined: 24 May 2005
Posts: 53
Location: Kingston, Ontario, Canada

canada.gif
PostPosted: Sat Feb 02, 2008 10:15 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum