--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi,
in front a Tip:
avoid public and private vars, it lead to a bad programming style.
Instead use LOCAL variable as long as ever possible.
For the RARE cases you really need a 'global' variable, you can work with a
'global' static, which is valid only for this prg.
BTW, give variables a more specific name, for what this var is.
I further like to add a prefix', so i can immediate read what type this var should content.
Therefor i use a 'simplified' hungarian notation:
that letter given by VALTYPE( variable ) in lowercase as prefix for the name ......
So for your question:
declare OUTSIDE the functions ONE time a MEMVAR statement,
then the compiler know that 'g' is a public/ private in this ! example.prg,
for all places the compiler does not find another variable declaration of same name
IMHO bad style:
--
MEMVAR g
proc main
public g
g := "this a global variable"
myproc()
return
proc myproc
? g
return
proc myproc2
LOCAL g := 'this will hide here the public var'
? g
return
--
best version:
--
PROC main
LOCAL cText := "this a global variable"
cText := myfunc( cText )
? cText
return
FUNCTION myproc( cText )
? cText
cText := "my now changed text"
RETURN cMyText
--
with a prg-wide global static
--
STATIC cMyText
PROC main
cMyText := 'this a prg-wide static variable'
myproc()
RETURN
PROC myproc
? cMyText
cMyText := "my new text"
RETURN
--
HTH -- and excuse, only 'my way' as a suggest
regards
Rolf