Jump to content

with "AU3Check" Variables declared with Assign("VarName") can't be accessed using $VarName?


Recommended Posts

Hello,

From the help file for function Assign():

 

Remarks

If there is a need to use Assign() to create/write to a variable, then in most situations, Eval() should be used to read the variable and IsDeclared() should be used to check that the variable exists.

 

 

 

 

Looks like eval() only has to be used to access "assign() created variable values", if the script doesn't define #AutoIt3Wrapper_Run_AU3Check=n ?

 

This is working fine:

$Key="S7_IP"
$result=Assign($Key,"test"); I'd expect the variable $S7_IP to exist from now on?
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $result = ' & $result & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$Result=IsDeclared($Key) ; does this test for the existance of variable "S7_IP"? The messagebox example code generated by code wizzard looks like that....
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Result = ' & $Result & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$result=IsDeclared("S7_IP")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $result = ' & $result & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\Assign-Test2.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
@@ Debug(5) : $result = 1
>Error code: 0
@@ Debug(8) : $Result = 1
>Error code: 0
@@ Debug(11) : $result = 1
>Error code: 0
+>12:38:13 AutoIt3.exe ended.rc:0

 

This one doesn't:

$Key="S7_IP"
$result=Assign($Key,"test"); I'd expect the variable $S7_IP to exist from now on?
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $result = ' & $result & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$Result=IsDeclared($Key) ; does this test for the existance of variable "S7_IP"? The messagebox example code generated by code wizzard looks like that....
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Result = ' & $Result & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$result=IsDeclared("S7_IP")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $result = ' & $result & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

ConsoleWrite($S7_IP & @CRLF)
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\temp\Assign-Test2.au3
"C:\temp\Assign-Test2.au3"(13,21) : warning: $S7_IP: possibly used before declaration.
ConsoleWrite($S7_IP &
~~~~~~~~~~~~~~~~~~~~^
"C:\temp\Assign-Test2.au3"(13,21) : error: $S7_IP: undeclared global variable.
ConsoleWrite($S7_IP &
~~~~~~~~~~~~~~~~~~~~^
C:\temp\Assign-Test2.au3 - 1 error(s), 1 warning(s)
!>12:39:43 AU3Check ended. Press F4 to jump to next error.rc:2

SciTE <F5> (run script) and <F7> (compile) are giving the same result.

 

I have to add #AutoIt3Wrapper_Run_AU3Check=n to my script.

So it looks like, that AU3Check is not aware of "assigned" varibles when doing its checkings? WAD?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_AU3Check=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


$Key="S7_IP"
$result=Assign($Key,"test"); I'd expect the variable $S7_IP to exist from now on?
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $result = ' & $result & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$Result=IsDeclared($Key) ; does this test for the existance of variable "S7_IP"? The messagebox example code generated by code wizzard looks like that....
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Result = ' & $Result & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$result=IsDeclared("S7_IP")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $result = ' & $result & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

MsgBox(0,"Is declared: $S7_IP",$S7_IP)
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\Assign-Test2.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
@@ Debug(8) : $result = 1
>Error code: 0
@@ Debug(11) : $Result = 1
>Error code: 0
@@ Debug(14) : $result = 1
>Error code: 0
+>12:42:42 AutoIt3.exe ended.rc:0

Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites
  • Developers

This is simply because au3check doesn't execute the code so has no way of knowing that you created that variable with Assign().

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
  • Developers

Just add a #forcedef to avoid the error in case you are sue things are correct like this:

#forcedef $S7_IP

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...