PureBasic Modules: A Quick Tutorial

Share your advanced PureBasic knowledge/code with the community.
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: PureBasic Modules: A Quick Tutorial

Post by DontTalkToMe »

Code: Select all

DeclareModule myModule
EndDeclareModule

Module myModule 
  Define myVar = 123
EndModule

Debug myModule::myVar   ; == 0 ?

However, you'd notice that the resulting output is still zero. Why is this?
The output can't be be zero since the code is not valid.
myVar is local to the module and it's not accessible from the external debug statement.

Less important, but I would add a .f to

Code: Select all

Global myVersionNumber = 1.23
since it's a float in the example after that which is a variation of this one.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 336
Joined: Mon Jul 08, 2013 8:43 pm

Re: PureBasic Modules: A Quick Tutorial

Post by minimy »

Wauuuu master TI, thanks for this very comprensive tutorial!!!
As allways PBforum is the best!!
Great community with a lot of gray matter!!

I now can put, halt and catch fire like a module in my HAL9000 :mrgreen: :mrgreen: HAHAHA

THANKS AGAIN TI!!! +1
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
chikega
User
User
Posts: 34
Joined: Fri Dec 04, 2020 3:19 am

Re: PureBasic Modules: A Quick Tutorial

Post by chikega »

Very nice tutorial on Modules! It's been added to my PureBasic Evernote Notebook 8)
Gary E Chike DMD MS
'Experience is what you get when you don't get what you want' Image
salutcava
User
User
Posts: 10
Joined: Fri May 03, 2013 10:50 am

Re: PureBasic Modules: A Quick Tutorial

Post by salutcava »

Hello,
Tanks for your quick & simple tutorial on the use of modules. I had read it mostly for the interoperability section (would like to call a procedure in the parent/main code from code in a module) for my needs. Since the use of a common/dummy module wasnt helping me (or couldnt figure out how and don't want my whole code to be contained in modules). I post here a "workaround" to call a procedure which is in the main code from a line of code contained inside a module :

Code: Select all

Procedure MainProcedure(arg.s)
	debug arg
EndProcedure

DeclareModule MyModule
	Prototype proto(argument.s)
	Global MainProc.proto=0
	;.
	;.
	;.
EndDeclareModule

Module MyModule
	Procedure ModuleProcedure(...)
		;.
		;.
		;.
		MainProc(text$)
		;.
		;.
		;.
	EndProcedure
EndModule

;.
;.
;.

MyModule::MainProc = @MainProcedure()

;.
;.
;.

End

Hope it will help. Bye !
User avatar
lgb-this
User
User
Posts: 28
Joined: Sat Aug 30, 2014 9:00 pm
Location: Switzerland
Contact:

Re: PureBasic Modules: A Quick Tutorial

Post by lgb-this »

salutcava wrote: Mon Mar 20, 2023 11:33 am Hope it will help. Bye !
Brilliant ! I was looking for this topic: "call an external procedure in a module" and your proposal worked !
KarLKoX
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Re: PureBasic Modules: A Quick Tutorial

Post by KarLKoX »

Very nice tutorial ! 👍

There is a tiny typo error :
"The variable myPrivateVariable and the function myPrivateFunction() are both inaccessible to the parent program"

To be changed to :

The variable myPrivateVariable and the function myPrivateProcedure() are both inaccessible to the parent program
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
Post Reply