Modules Subprocedure Subfunction

General discussion on mikroBasic.
Post Reply
Author
Message
k.ifantidis
Posts: 15
Joined: 23 Nov 2012 23:17

Modules Subprocedure Subfunction

#1 Post by k.ifantidis » 26 Nov 2015 14:37

Hello i would like to ask someone to help me understand how to put a subroutine or subfunction in a module and being able to call it from the main program. Also i would like to declare the variables that ill use in the module as Global Variables.

I tried using this code from XOR (POST#2) http://www.mikroe.com/forum/viewtopic.p ... all#p29064.

But it didn't work.

Any help would be nice.
Regards, Kostas.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Modules Subprocedure Subfunction

#2 Post by janni » 27 Nov 2015 02:43

xor's post dates before mB PRO was introduced, so there's no mention of routines' prototypes that need to be added for visibility from outside of the module. You should have a look at 'Program Organisation' chapter in Help but for a quick reference here's slightly modified xor's module example

Code: Select all

module My_New_Module

dim modvar1, modvar2 as byte  ' variables visible to code that included the module

sub procedure PORTB_LED       ' prototype making procedure visible to code that included the module

Implements

dim modvar3 as byte           ' variable local to module

sub procedure delay_1second   ' local procedure
  delay_ms(1000)
end sub

sub procedure PORTB_LED
  modvar1 = $FF
  modvar2 = 0
  modvar3 = %10101010
  PORTB = modvar1
  delay_1second
  PORTB = modvar2
  delay_1second
  PORTB = modvar3
end sub

end.

k.ifantidis
Posts: 15
Joined: 23 Nov 2012 23:17

Re: Modules Subprocedure Subfunction

#3 Post by k.ifantidis » 29 Nov 2015 00:00

Thank you for helping me and for the reply !

Best Regards, Kostas.

Post Reply

Return to “mikroBasic General”