frew Posted April 27, 2009 Share Posted April 27, 2009 (edited) Hello, Why does $y3 = $y2 - 100 not create the variable $y3 in the If statement below? Variable not declared error comes about apparently because I try to create a new variable inside an If statement, like this, for example: If $y2 < $y1 Then $y3 = $y2 - 100 ;this does not create the variable $y3 as I thought it would EndIf If $y3 > 716 Then ;error says that this variable is trying to be used without being declared $y3 = 716 EndIf Solution: I put Dim $y3 at the top of the script. (but I didn't think that was supposed to be necessary, because generally I have been able to just create variables as I go along anywhere in the script.) Thanks for any ideas about this. frew Edited April 27, 2009 by frew Link to comment Share on other sites More sharing options...
Valuater Posted April 27, 2009 Share Posted April 27, 2009 Maybe because it is not ABSOLUTE that $y2 < $y1. If not then the next If/test is invalid because $y3 was never created 8) Link to comment Share on other sites More sharing options...
frew Posted April 27, 2009 Author Share Posted April 27, 2009 Maybe because it is not ABSOLUTE that $y2 < $y1. If not then the next If/test is invalid because $y3 was never createdAh, yes...thank you Valuater, that makes sense. I guess then it's a good rule of thumb to not try to create variables inside If statements.Okay, if I do If statements like this, I guess I just have to be sure to declare any variables that may be created inside the Ifsoutside the Ifs. Like with a Dim above the If statement.Thank you very much,frew Link to comment Share on other sites More sharing options...
Valuater Posted April 27, 2009 Share Posted April 27, 2009 (edited) Welcome!As I understand it is better to use Global rather than Dim per Dev's here.... and remember to use Local rather than Global for example inside a function.8) Edited April 27, 2009 by Valuater Link to comment Share on other sites More sharing options...
frew Posted April 27, 2009 Author Share Posted April 27, 2009 As I understand it is better to use Global rather than Dim per Dev's here.... and remember to use Local rather than Global for example inside a function.That's good to know, thanks.I see so much Dim around in much code examples, I thought maybe that was the way to go.Okay, Global and Local...Global for when a variable's value is the same throughout the script, and Local for when the variable's value may change throughout the script...I think that's the idea.I'll study that in the help I guess...because I may be mixing that up with Constants, sorry.Thanks, I'll look into that.frew Link to comment Share on other sites More sharing options...
Valuater Posted April 27, 2009 Share Posted April 27, 2009 You are mixing them slightly . so yea, have a look in the help file, it's pretty good!! 8) 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