Page 1 of 1

Global variable not seen in procedure

Posted: Thu Jul 28, 2016 9:22 am
by woki
A global variable filled from native javascript is not seen in
a procedure - is this correct ?

Code: Select all

Global sip.s=""
Global test.s=""

! var v_sip = location.host;

test = "hello"

Debug sip + " - " + test

Procedure vartest()
  
  Debug sip + " - " + test
  
EndProcedure

Debug sip + " - " + test

vartest()

Debug sip + " - " + test
Regards
Wolfgang

Re: Global variable not seen in procedure

Posted: Thu Jul 28, 2016 9:26 am
by Fred
You are redeclaring the variable if you use the 'var' prefix. Here is the correct code:

Code: Select all

Global sip.s=""
Global test.s=""

! v_sip = location.host;

test = "hello"

Debug sip + " - " + test

Procedure vartest()
 
  Debug sip + " - " + test
 
EndProcedure

Debug sip + " - " + test

vartest()

Debug sip + " - " + test

Re: Global variable not seen in procedure

Posted: Thu Jul 28, 2016 9:53 am
by woki
That makes sense - thank you Fred.