DarkBoost Posted June 21, 2008 Share Posted June 21, 2008 I have a script running which is throwing me a message: Variable used without being declared I am still new to programming and its methodolical rules, but slowly getting there. It simply goes: If $A = $B Then $C = 1 EndIf MsgBox(0,"","The Number is "&$C) Link to comment Share on other sites More sharing options...
Anonymouse Posted June 21, 2008 Share Posted June 21, 2008 I have a script running which is throwing me a message: Variable used without being declaredI am still new to programming and its methodolical rules, but slowly getting there.It simply goes:If $A = $B Then$C = 1EndIfMsgBox(0,"","The Number is "&$C)That doesn't even make sense. What's the value of B?and you have to declare your variables, look up Local, Dim, Global children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :) Link to comment Share on other sites More sharing options...
DarkBoost Posted June 21, 2008 Author Share Posted June 21, 2008 That doesn't even make sense. What's the value of B?and you have to declare your variables, look up Local, Dim, GlobalIt doesn't matter what $A and $B are its irrelavant to the example... doesn't matter, will check the help file again.Thanks anyways. Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 21, 2008 Share Posted June 21, 2008 Yes, variables are very relevant. If you don't post code that shows the problem, how do you expect us to fix it? Link to comment Share on other sites More sharing options...
muncherw Posted June 21, 2008 Share Posted June 21, 2008 I have a script running which is throwing me a message: Variable used without being declared I am still new to programming and its methodolical rules, but slowly getting there. It simply goes: If $A = $B Then $C = 1 EndIf MsgBox(0,"","The Number is "&$C) It means that your variables have to be equal to something before you start using them. $A = 1 $B = 2 If $A = $B Then $C = 1 EndIf MsgBox(0,"","The Number is "&$C) If they aren't set to anything how does the program know if $A = $B? Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic] Link to comment Share on other sites More sharing options...
DarkBoost Posted June 21, 2008 Author Share Posted June 21, 2008 (edited) My apologises. I have given the appearance that I do not understand variables due to not showing what $A and $B is declared as in my original example, my bad! Let me rephrase: Can you declare a variable during an IF statement? example: If FileExists("c:\example1.txt") Then $var = "red" EndIf If FileExists("c:\example2.txt") Then $var = "blue" EndIf If FileExists("c:\example3.txt") Then $var = "green" EndIf MsgBox(0,"","The colour is now "&$var); only 1 of the above files will ever exist From muncherw's post, obviously No it needs to be declared outside the If Statement. However the above works on Windows XP but fails on Vista 64bit with my original post: Variable used without being declared Is there better way to write this, is this something that array or loop might be useful for? Edited June 21, 2008 by DarkBoost Link to comment Share on other sites More sharing options...
muncherw Posted June 21, 2008 Share Posted June 21, 2008 Let me rephrase:Can you declare a variable during an IF statement? example:Yes you absolutely can do that. Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic] Link to comment Share on other sites More sharing options...
muncherw Posted June 21, 2008 Share Posted June 21, 2008 However the above works on Windows XP but fails on Vista 64bit with my original post: Variable used without being declaredMaybe it has something to do with Vista. *shrug* Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic] Link to comment Share on other sites More sharing options...
DarkBoost Posted June 21, 2008 Author Share Posted June 21, 2008 Yes you absolutely can do that.Thats what I thought and this works with Windows XP 32bit and Windows Vista Ultimate 32bitbut now failing with Windows Vista Ultimate 64bit it this an incompatible issue with AutoIT and Vista Ultimate 64bit? Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 21, 2008 Share Posted June 21, 2008 No, you are probably doing something wrong. AutoIt works on Vista. Vista just doesn't work. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 21, 2008 Share Posted June 21, 2008 Thats what I thought and this works with Windows XP 32bit and Windows Vista Ultimate 32bitbut now failing with Windows Vista Ultimate 64bit it this an incompatible issue with AutoIT and Vista Ultimate 64bit?There shouldn't be a "incompatible issue". Have you tried the things noted in the helpfile? Things like=Did you run the script as administrator?Used the #requireadmin?Disabled UAC? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
NELyon Posted June 21, 2008 Share Posted June 21, 2008 (edited) There shouldn't be a "incompatible issue". Have you tried the things noted in the helpfile? Things like=Did you run the script as administrator?Used the #requireadmin?Disabled UAC?Or there's the obvious question. Do the files exist?! It's obvious that with his code, the variables are only declared if the files exist I.E, no "Else" statement.EDIT:AutoIt works on Vista. Vista just doesn't work.Amen. Edited June 21, 2008 by KentonBomb Link to comment Share on other sites More sharing options...
DarkBoost Posted June 21, 2008 Author Share Posted June 21, 2008 (edited) I have run the script as an Administrator and tested with the #RequireAdmin included and UAC has always been disabled.To my understanding, the IF statement should always default as TRUE unless specified, so if the FileExists = True thenit should run whatever is declared in the Then statement otherwise it will EndIf. Please let me know if this is not correct.I have attached a screenshot of the code including the exact error (maybe this will help?) Update: This is failing for both Windows Vista Ultimate 32bit and 64bit... this is only working for Windows XP 32bitAny ideas? Edited June 21, 2008 by DarkBoost Link to comment Share on other sites More sharing options...
TerryOwen Posted June 21, 2008 Share Posted June 21, 2008 I have run the script as an Administrator and tested with the #RequireAdmin included and UAC has always been disabled.To my understanding, the IF statement should always default as TRUE unless specified, so if the FileExists = True thenit should run whatever is declared in the Then statement otherwise it will EndIf. Please let me know if this is not correct.I have attached a screenshot of the code including the exact error (maybe this will help?) Update: This is failing for both Windows Vista Ultimate 32bit and 64bit... this is only working for Windows XP 32bitAny ideas?I'm also a total AI beginner and I don't know anything about Vista but that said... If you are doing these If statements and say number 2 is true, then if it gets to number 3, then it's false again. Does AI have a Case or Select statement? From other languages I've used, you need to drop out of the eval mode when a statement is true. I'm running into the undeclared variable thing using old code with latest AI, so if you are using any includes, maybe that's where the problem is? Terry Link to comment Share on other sites More sharing options...
MHz Posted June 21, 2008 Share Posted June 21, 2008 Let me rephrase: Can you declare a variable during an IF statement? example: If FileExists("c:\example1.txt") Then $var = "red" EndIf If FileExists("c:\example2.txt") Then $var = "blue" EndIf If FileExists("c:\example3.txt") Then $var = "green" EndIf MsgBox(0,"","The colour is now "&$var); only 1 of the above files will ever existSomeone said ABSOLUTELY YES. So what happens when every condition fails? The state of $var is... Link to comment Share on other sites More sharing options...
DarkBoost Posted June 21, 2008 Author Share Posted June 21, 2008 I thought that if an If statement which only includes Then would skip the Then if it renders False? Example: If FileExists("c:\Example1.txt") Then; This file does not exist so statement = False $var = "red"; This line is never read because the above statement = False EndIf If FileExists("c:\Example2.txt") Then; This file does exists so statement = True $var = "blue"; This line is read because the above statement = True EndIf MsgBox(0,"","The Colour is now "&$var); The answer would be 'blue' because $var was declared in the second IF statement as it rendered True Sorry guys, I am just trying to understand how AutoIt works. Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 21, 2008 Share Posted June 21, 2008 Correct. If the statement is false, the block is not executed. You must always handle the chance that it isn't true though. Just say $var = "" before the blocks, that way you always know it's declared, in the case that none of your files exist. Applied to this example anyways. Link to comment Share on other sites More sharing options...
DarkBoost Posted June 21, 2008 Author Share Posted June 21, 2008 Richard Robertson This makes sense, thanks! Link to comment Share on other sites More sharing options...
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