[PB520B14] DeclareModul and Define (Done, not Bug)

Just starting out? Need help? Post your questions and find answers here.
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

[PB520B14] DeclareModul and Define (Done, not Bug)

Post by mk-soft »

Invalid starting value within modules

Code: Select all

DeclareModule myTest
  
  Define var1.i = 1
  ;Global var1.i = 1
  
  Declare foo()
  
EndDeclareModule

Module myTest
  
  Procedure foo()
    
    Protected iTemp
    iTemp = var1
    Debug "foo(): " + iTemp
    
  EndProcedure
  
EndModule

; Test
UseModule myTest
foo()
Debug "Debug: " + var1
UnuseModule myTest

myTest::foo()
Debug "Debug: " + myTest::var1
Last edited by mk-soft on Thu Aug 29, 2013 9:40 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Little John
Addict
Addict
Posts: 4791
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: [PB520B14] DeclareModul and Define

Post by Little John »

mk-soft wrote:Invalid starting value within modules
What output do you get?
Exactly which part of the output did you not expect?
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: [PB520B14] DeclareModul and Define

Post by luis »

Code: Select all

foo(): 0
Debug: 1
foo(): 0
Debug: 1
What's the problem ?
"Have you tried turning it off and on again ?"
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [PB520B14] DeclareModul and Define

Post by mk-soft »

Different values ​​for "var1". Internal maintenance of the procedure foo is the value of the varible zero. Outside of Procedure, the starting value of the variable.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: [PB520B14] DeclareModul and Define

Post by luis »

Uhm... are you saying the problem is var1 is ZERO inside the proc and 1 outside ?

Define is not global, so it's normal that inside the proc var1 is zero.
But define is local to the module's scope, so if you print the value of var1 outside of the proc it's 1.
Try to put an EnableExplicit inside declaremodule.
"Have you tried turning it off and on again ?"
Little John
Addict
Addict
Posts: 4791
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: [PB520B14] DeclareModul and Define

Post by Little John »

mk-soft wrote:Different values ​​for "var1". Internal maintenance of the procedure foo is the value of the varible zero. Outside of Procedure, the starting value of the variable.
:?: I'm not able to understand this text.

I'm getting the same output as Luis, and don't see any problem as well.
Maybe using EnableExplicit will help you to understand what's going on.
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [PB520B14] DeclareModul and Define

Post by mk-soft »

Just found myself. Sorry, not a bug.

Define in modules somehow make no sense
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: [PB520B14] DeclareModul and Define

Post by luis »

mk-soft wrote: Define in modules somehow make no sense
It does exactly what it does outside the modules.
A local variable, not a global one and not one visible inside a procedure unless you use Shared.

Code: Select all

 
Define var1.i = 1

 Procedure foo()
  Protected iTemp
  iTemp = var1
  Debug "foo(): " + iTemp   
 EndProcedure
 
foo()
Debug "Debug: " + var1
"Have you tried turning it off and on again ?"
Post Reply