Page 2 of 2

Re: PureBasic Modules: A Quick Tutorial

Posted: Sat Jun 02, 2018 4:07 pm
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.

Re: PureBasic Modules: A Quick Tutorial

Posted: Sun Aug 26, 2018 12:23 pm
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

Re: PureBasic Modules: A Quick Tutorial

Posted: Sun Oct 03, 2021 6:02 am
by chikega
Very nice tutorial on Modules! It's been added to my PureBasic Evernote Notebook 8)

Re: PureBasic Modules: A Quick Tutorial

Posted: Mon Mar 20, 2023 11:33 am
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 !

Re: PureBasic Modules: A Quick Tutorial

Posted: Sat Apr 01, 2023 1:55 pm
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 !

Re: PureBasic Modules: A Quick Tutorial

Posted: Wed Jan 24, 2024 1:57 am
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