Sign in to follow this  
Followers 0
Shane0000

Assign() giving errors (Not Declared etc)

14 posts in this topic

Im using assign to call some variables and at runtime I am getting errors:

WARNING: $Reserve_1: possibly used before declaration.

ERROR: $Reserve_1: undeclared global variable.

The code below is how I assign the vars, and I used a 'IsDeclared' to verify that it was successful.

Im trying to clean/convert old code and I would like to get rid of these 60 errors and 60 warnings thanks.

For $i = 1 to 60
if not Assign ( "Reserve_"&$i, "",2) then
  MsgBox(0,"Error Assigning :","Reserve_"&$i)
else
  ;MsgBox(0,"Assigning :","Reserve_"&$i)
EndIf
Next
msgbox(0,'IsDeclared ( Reserve_58 )',IsDeclared ( 'Reserve_58' ))

Share this post


Link to post
Share on other sites



Au3Check is giving the error message because it has no way to tell that there's a valid variable called $Reserve_58, so it errors out. Here's a way to get around it using Eval.

For $i = 1 To 60
     If Not Assign("Reserve_" & $i, $I, 2) Then
          MsgBox(0, "Error Assigning :", "Reserve_" & $i)
     Else
          ;MsgBox(0,"Assigning :","Reserve_"&$i)
     EndIf
Next
MsgBox(0, 'IsDeclared ( Reserve_58 )', Eval('Reserve_58')) ;<<<<<<<<<<<<<<<<<<<<< No error generated this way.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

shane0000,

I appears that you are trying to assign a variable with no data. czardas's example works because he is assigning the value of $i to the variable being created.

kylomas

edit: additional info - assign issues a return code.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Neither of these methods removed the error @ run time. Console area.

My intent was to lessen the clutter as there are some out of date funcs giving errors also. This alone is generating 120 error/warnings.

Thanks for the help.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

kylomas, Yes I am using the same way I would use 'Dim $Reserve_58'. I read in data from a file later to assign the values to alot of diferent vars that are Dim'ed as above ('Dim $sSomeVar') aswell as the 60 $Reserve vars.

The code runs fine, it just generates alot of errors at runtime (in autoit console).

Thanks

Edited by Shane0000

Share this post


Link to post
Share on other sites

shane0000,

I'm doing some more testing. It looks like what you are doing should have worked. Did you try what BrewmanNH suggested?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

shane0000 (f.y.i),

I ran this code to verify that your syntax is correct.

local $ret
For $i = 1 to 60
 $ret = Assign ( "Reserve_"&$i, "",2)
 consolewrite($ret & " | " )
Next

"success" was returned for each assign

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Yeah I tried them both, And I understand that its just going to have to remain.

BrewmanNH stated that the compiler has noway to know that the vars are being declared in such away.

And I can see that now, the compiler cant pre run the code to assign and verify that the vars had been declared. Thats like Inception I think, :) a compiler within a compiler.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

That works,

This Errors out in console

local $ret
local $thisVar
For $i = 1 to 60
$ret = Assign ( "Reserve_"&$i, "",2)
consolewrite($ret & " | " )
Next
$thisVar = $Reserve50

Because the compiler has no way to know that later on, $reserve50 will actually be a valid Var.

It just sees that $reserve50 has been called, but not set by standard ways, dim/local/global.

Edited by Shane0000

Share this post


Link to post
Share on other sites

shane0000,

Yes, I see that but vaguely recall a compiler directive for just this case.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Wouldn't it just be easier to use an array for what you want to do?

Dim $Reserve[61]
$Reserve[0] = 60

For $i = 1 To $Reserve[0]
    $Reserve[$i] = $i
Next

$thisVar = $Reserve[50]
MsgBox(0, "", $thisVar)

Share this post


Link to post
Share on other sites

Yeah, I think thats what I should do czardas. I wrote this about 5 years ago , I dunno why I did it like this hehe.

There is like 1400 lines of code and Im trying to go back and figure out what all does what again.

Thanks for the help and info

Share this post


Link to post
Share on other sites

As the help file says under Assign, if you have to use Assign to create the variables, then it's best to use Eval and IsDeclared to access them later. You CAN access them directly, but you are going to get Au3Check error messages.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


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
Sign in to follow this  
Followers 0

  • Similar Content

    • aleeksunder
      By aleeksunder
      Hello!
      Can anyone explain what's going on here:
      ; Initializing an array Local $a = [ 0 ] ; Lately in code I want to assign new array to $a variable $a = [ 1 ] and got this error at compile time
      ==> Error in expression.: $a = [ 1 ] $a = ^ ERROR What is it and why?
      And I've mentioned that I can't pass "manual" array to function as parameter:
      a( [ 0 ] ) Func a( $a ) _ArrayDisplay( $a ) EndFunc still the same error
      ==> Error in expression.: a( [ 0 ] ) a( ^ ERROR  
    • algiuxas
      By algiuxas
      Hello,
      I need to assign data to array:
      Global $Test[3][4] $Array = "Test" SetArrayData($Array,"Hello world!",1,3) ConsoleWrite($Array[1][3]&@CRLF) Exit Func SetArrayData($Array,$Data,$1,$2) $Array[$1][$2] = $Data; <-- ??? EndFunc I need that somebody would help me with that function
    • WannaBeGut
      By WannaBeGut
      Hello!
      I havent found any solution for my problem in the Internet or on the Forum, excuse me If i overlooked something.
      For $i = 1 To 5 Assign("oGoogle"&$i, _IECreate("google.com" 0, 1, 0, 0)) $GoogleVar = $oGoogle&$i Assign("oSearchInput"&$i, _IEGetObjById($GoogleVar, "lst-ib")) Next What I'am trying to do is open Google.com 5 times with _IECreate and assign it to the Variables "$oGoogle1, $oGoogle2,...", but I have to use these Variables again, because I want to assign the Searchinputs from every $oGoogle to another Variable ($oSearchInput1, $oSearchInput2,...). But if i try to use this code, Autoit tells me that $oGoogle is not declared!
      I hope someone is willing to help me! (Excuse my Grammar )
    • Schoening
      By Schoening
      While i am waiting for Better Solutions for Finding Multiple @error Cases and React according to them, i am hoping that some1 could explain me what my problem in this (time consuming) function is..

      The Idea is that i check for @Errors from the 3 PixelSearch i am doing, and give Message according to it.
      I am changing Colors In Paint for Every Loop To Test If the Color Searches Are Correct.
      All Cases are Working Fine, and the Right MsgBoxes are Triggered, Except the Case where all 3 Colors are Missing:


      HotKeySet("{ESC}", "End") Global $pixelSearchError1 = @error Global $pixelSearchError2 = @error Global $pixelSearchError3 = @error While 1 Sleep(10) $pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10) ;Blue $pixelSearchError1 = @error $pixelsearch2 = PixelSearch(250,310,400,512,0xfa0000,10) ;Red $pixelSearchError2 = @error $pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10) ;Green $pixelSearchError3 = @error Call("_errorcheck") WEnd Func _errorcheck() Sleep(100) Select ;Check for Blue Color, Then Proceed. Case Not $pixelSearchError1 ;Found Blue MsgBox(0,"Message","Blue Pixel Found!") Select ;Blue Found. Now check for Red Case Not $pixelSearchError2 ;Found Blue and Red MsgBox(0,"Message","Blue and Red Pixel Found!") Select ;Blue and Red found. Now check for Green Case Not $pixelSearchError3 ;Found Blue, Red and Green MsgBox(0,"Message","Blue,Red and Green Pixel Found!") Case $pixelSearchError3 ;Blue, Red But not Green MsgBox(0,"Message","Found Blue, Red But Not Green") EndSelect Case $pixelSearchError2 ;Blue Found, But Not Red MsgBox(0,"Message","Blue Found, But Not Red") Select ;Blue and Red found. Now check for Green Case Not $pixelSearchError3 ;Found Blue, Green But not Red MsgBox(0,"Message","Found Blue, Green But Not Red") Case $pixelSearchError3 ;Blue, But not Red or Green MsgBox(0,"Message","Could only Find Blue") EndSelect EndSelect Case $pixelSearchError1 ;Blue Not Found MsgBox(0,"Message","Blue Pixel Not Found") Select ;Blue Not Found. Now check for Red Case Not $pixelSearchError2 ;Found Red, But not Blue MsgBox(0,"Message","Found Red, But not Blue") Select ;Found Red, But not Blue Now check for Green Case Not $pixelSearchError3 ;Red and Green, but not Blue MsgBox(0,"Message","Red,Green But not Blue") Case $pixelSearchError3 ;Red, But not Blue or Green MsgBox(0,"Message","Could only Find Red") EndSelect Case $pixelSearchError2 ;Could not find Blue or Red MsgBox(0,"Message","Could not Find Blue and Red") Select ;Blue and Red Not found. Now check for Green Case Not $pixelsearch3 ;Only found Green MsgBox(0,"Message","Only found Green") Case $pixelSearchError3 ;Did not Find Blue,Red or Green MsgBox(0,"Message","No Color was found") EndSelect EndSelect EndSelect Sleep(10) EndFunc
      I Made a Picture that should make it far easier to see where one Select Case Starts and Ends Check the Link Below.
      http://imageshack.us/f/9/selectcasegreenerror.gif/

      I can't see why the Last Case is not working.. When Blue,Red AND Green are Missing i still get the "Only found Green"
      Please Help

      Also, Building the Cases Like this takes up allot of Time and Space, so if you have a Easier way please Tell
      Like:

      If Not @error 1 And @error 2 And @error 3 Then
      But i don't think that Works.

      I probably want to run 5 PixelSearches and that would mean 5 Select an 32 Cases !!!1!!11
      So it would be Great if there was another way of doing this
      If not, Please do still tell what the problem of my Function is