Global variable not seen in procedure

Just starting out? Need help? Post your questions and find answers here.
woki
Posts: 13
Joined: Tue Feb 25, 2014 7:52 pm

Global variable not seen in procedure

Post 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
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: Global variable not seen in procedure

Post 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
woki
Posts: 13
Joined: Tue Feb 25, 2014 7:52 pm

Re: Global variable not seen in procedure

Post by woki »

That makes sense - thank you Fred.
Post Reply