gerwim Posted April 27, 2011 Posted April 27, 2011 (edited) Hi there, For some reason AutoIt says "Variable used without being declared" when it definately is declared: Global $vConfigLocation $vConfigLocation = IniRead(@AppDataDir & "\locations.ini", "Locations", @AutoItExe, "notfound") if ($vConfigLocation = "notfound") Then MsgBox(16, "Error", "Could not read the locations file. Make sure your %appdata% folder is writeable.") Exit Else $vConfigLocation = @AppDataDir & "\" & $vConfigLocation & ".ini" EndIf Func ReadIni($veld) Local $vReturn = IniRead($vConfigLocation, "General", $veld, "notfound") if ($vReturn = "notfound") Then Return False Else Return $vReturn EndIf EndFunc ;==>ReadIni The error I get: Local $vReturn = IniRead($vConfigLocation, "General", $veld, "notfound") Local $vReturn = IniRead(^ ERROR Anyone knows what the problem is? Edited April 27, 2011 by gerwim
DarkestHour Posted April 27, 2011 Posted April 27, 2011 Just copy and pasting your code into scite does not generate that error you are getting. Even if i call your ReadIni Function. Is there a larger piece of code this belongs to?
gerwim Posted April 27, 2011 Author Posted April 27, 2011 Hmm, strange. My bad. Yes, there is a bigger code, but just Functions which should not interfere with this. Nothing has anything todo with these variables.
gerwim Posted April 27, 2011 Author Posted April 27, 2011 And the most strange thing is, the function below - WriteIni - works. Even it uses the same variable: Func WriteIni($veld, $data) IniWrite($vConfigLocation, "General", $veld, $data) EndFunc ;==>WriteIni
DarkestHour Posted April 27, 2011 Posted April 27, 2011 As a thought, perhaps it is because you are calling it a local variable, try setting it to Global instead and see what happens.
gerwim Posted April 27, 2011 Author Posted April 27, 2011 No, it is set as Global (see the very first line of my code).
czardas Posted April 27, 2011 Posted April 27, 2011 (edited) It could be the variable $void that hasn't been declared.Edit Something that puzzles me: I don't understand the reason for the function ReadIni - why write another IniRead function? Edited April 27, 2011 by czardas operator64 ArrayWorkshop
DarkestHour Posted April 27, 2011 Posted April 27, 2011 Well, i am at a loss as to what is causing your problem since i am unable to reproduce your error.
gerwim Posted April 27, 2011 Author Posted April 27, 2011 It could be the variable $void that hasn't been declared.Edit Something that puzzles me: I don't understand the reason for the function ReadIni - why write another IniRead function?There's no variable "$void", but "$veld". "$veld" is passed through the function.Since I'm using a (global) function to have one path (I prefer that over variables).Well, i am at a loss as to what is causing your problem since i am unable to reproduce your error.Yes, I'm afraid I can't post the complete code, but I'll try to strip things off to see what causes it.
czardas Posted April 27, 2011 Posted April 27, 2011 (edited) There's no variable "$void", but "$veld". "$veld" is passed through the function.Since I'm using a (global) function to have one path (I prefer that over variables).Yes, I'm afraid I can't post the complete code, but I'll try to strip things off to see what causes it.Sorry the screen I use makes my eyes tired sometimes. Guess I need glasses. $veld could be the variable that hasn't been declared. I don't see where you declare it. Edited April 27, 2011 by czardas operator64 ArrayWorkshop
gerwim Posted April 27, 2011 Author Posted April 27, 2011 Sorry the screen I use makes my eyes tired sometimes. Guess I need glasses. However the string "$veld" is written as a variable because it isn't wrapped in quotes. This will be interpreted as a variable that hasn't been declared, unless you write it as a string.Yes I know, but it's from the function itself. This is the correct way, and it works. The problem is the variable $vConfigLocation.
czardas Posted April 27, 2011 Posted April 27, 2011 (edited) Yes I know, but it's from the function itself. This is the correct way, and it works. The problem is the variable $vConfigLocation.I don't know, that seems okay to me. $vConfigLocation has been declared, so it has to be something else. The part we can't see is where $veld is declared. I mean you're not calling on the function in the code, so it's impossible to tell what's wrong. Edited April 27, 2011 by czardas operator64 ArrayWorkshop
gerwim Posted April 27, 2011 Author Posted April 27, 2011 Alright, got it. Silly error of mine. I define a complete Global variable list at the top of my script. So I had: Global $vAutoUpdate = ReadIni("autoupdate") Global $vAutoReconnect = ReadIni("autoreconnect") Global $vConfigLocation But that will call the function ReadIni which doesn't know $vConfigLocation (yet). Thanks all!
czardas Posted April 27, 2011 Posted April 27, 2011 (edited) Reorder the declarations this way to fix it.Global $vConfigLocation Global $vAutoUpdate = ReadIni("autoupdate") Global $vAutoReconnect = ReadIni("autoreconnect")Although this apparently fixes the error message, I'm not sure exactly how your code works, but you should declare your variables just before you use them. This may not have fixed all the problems you encounter with this code. You may need to order things differently. For example:Global $vConfigLocation $vConfigLocation = IniRead(@AppDataDir & "\locations.ini", "Locations", @AutoItExe, "notfound") if ($vConfigLocation = "notfound") Then MsgBox(16, "Error", "Could not read the locations file. Make sure your %appdata% folder is writeable.") ;Exit Else $vConfigLocation = @AppDataDir & "\" & $vConfigLocation & ".ini" EndIf Global $vAutoUpdate = ReadIni("autoupdate") Global $vAutoReconnect = ReadIni("autoreconnect") Func ReadIni($veld) Local $vReturn = IniRead($vConfigLocation, "General", $veld, "notfound") if ($vReturn = "notfound") Then Return False Else Return $vReturn EndIf EndFunc ;==>ReadIniEdit => I would also change the Global declarations to Local. I hope this fixes your problem. Edited April 27, 2011 by czardas operator64 ArrayWorkshop
odaylton Posted August 11, 2012 Posted August 11, 2012 english Portugues Translated by google (sorry for any mistakes) Traduzido pelo google (desculpe pelos eventuais erros) I had the same problem. I realized that the order of declaration is very important to see the example idiot: eu tive o mesmo problema. percebi que a ordem de declaração é muito importante veja o exemplo idiota: JanelaAtiva();Basta indicar o PID para usar a rotinaGlobal Const $hPSAPI = DllOpen("psapi.dll")Global Const $hKERNEL32 = DllOpen("kernel32.dll")Error$aProcessHandle = DllCall($hKERNEL32, "int", "OpenProcess", "int", 0x0400 + 0x0010, "int", 0, "int", $i_PID)$aProcessHandle = DllCall(^ ERROR Solution: Solução: Global Const $hPSAPI = DllOpen("psapi.dll")Global Const $hKERNEL32 = DllOpen("kernel32.dll") JanelaAtiva()
odaylton Posted August 11, 2012 Posted August 11, 2012 english PortuguesTranslated by google Traduzido pelo google(sorry for any mistakes) (desculpe pelos eventuais erros) I had the same problem. eu tive o mesmo problema.I realized that the order of declaration is very percebi que a ordem de declaração é muitoimportant to see the example idiot: importante veja o exemplo idiota:JanelaAtiva()Global Const $hPSAPI = DllOpen("psapi.dll")Global Const $hKERNEL32 = DllOpen("kernel32.dll")Error$aProcessHandle = DllCall($hKERNEL32, "int", "OpenProcess", "int", 0x0400 + 0x0010, "int", 0, "int", $i_PID)$aProcessHandle = DllCall(^ ERROR Solution: Solução: Global Const $hPSAPI = DllOpen("psapi.dll")Global Const $hKERNEL32 = DllOpen("kernel32.dll")JanelaAtiva()
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now