Jump to content

HotKeySet() and 'Variable used without being declared.'


ibecko
 Share

Go to solution Solved by Danp2,

Recommended Posts

hi, how I can globaly fix non declared variable issue when I run function from HotKeySet() ?

HotKeySet('{ESC}', 'function_test')

function_test()
function_test('blablabla')

Func function_test($var='')
   If     IsDeclared('var') then ConsoleWrite("when this function run like function_test() or function_test('var test') from code work fine, $var is declared, $var='"&$var&"', now press ESC"&@CRLF&@CRLF)
   If Not IsDeclared('var') then ConsoleWrite("when this function run pressing key from HotKeySet() $var not declred and script exit with error 'Variable used without being declared.'"&@CRLF&@CRLF)
   If Not IsDeclared('var') then ConsoleWrite("$var='"&$var&"'"&@CRLF&@CRLF)
EndFunc

While True
   Sleep(20)
WEnd

 

I know, its possible to add firt line on function where I check if variable is declared and if no declare it but why? I declare variable on function parameter and it works for scripts but no for HotKeySet

 

thanks

Link to comment
Share on other sites

no, I dont wanna call any function parameter from hotkeyset, try my code and press ESC

my question is: Func function_test($var='') has local declared  $var variable (only for this function) and why hotkeyset ignore this declaration

 

I must check declaration and redeclare $var again, then works fine, but this is duplicate declaration of local variable

HotKeySet('{ESC}', 'function_test')

function_test()
function_test('blablabla')

Func function_test($var='')
   If Not IsDeclared('var') then $var=''
   If     IsDeclared('var') then ConsoleWrite("when this function run like function_test() or function_test('var test') from code work fine, $var is declared, $var='"&$var&"', now press ESC"&@CRLF&@CRLF)
   If Not IsDeclared('var') then ConsoleWrite("when this function run pressing key from HotKeySet() $var not declred and script exit with error 'Variable used without being declared.'"&@CRLF&@CRLF)
   If Not IsDeclared('var') then ConsoleWrite("$var='"&$var&"'"&@CRLF&@CRLF)
EndFunc

While True
   Sleep(20)
WEnd

 

Link to comment
Share on other sites

25 minutes ago, Danp2 said:

You could use a 2nd function in the HotKeySet that calls the original function.

try this way

HotKeySet('{ESC}', 'function_ESC')

function_test()
function_test('blablabla')

Func function_test($var='')
   If Not IsDeclared('var') then $var=''
   If     IsDeclared('var') then ConsoleWrite("when this function run like function_test() or function_test('var test') from code work fine, $var is declared, $var='"&$var&"', now press ESC"&@CRLF&@CRLF)
   If Not IsDeclared('var') then ConsoleWrite("when this function run pressing key from HotKeySet() $var not declred and script exit with error 'Variable used without being declared.'"&@CRLF&@CRLF)
   If Not IsDeclared('var') then ConsoleWrite("$var='"&$var&"'"&@CRLF&@CRLF)
EndFunc

Func function_ESC()
    function_test('blablabla')
EndFunc


While True
   Sleep(20)
WEnd

 

I know that I know nothing

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...