adjist Posted January 26, 2020 Posted January 26, 2020 Hello all! Getting this error : (22) : ==> Variable used without being declared.: if $vNumber = 0 Then if ^ ERROR But I'm sure I have defined the variable, as in the top of my script has Global $vNumber = 0 How would I go about fixing this?
Earthshine Posted January 26, 2020 Posted January 26, 2020 First post your entire script My resources are limited. You must ask the right questions
adjist Posted January 26, 2020 Author Posted January 26, 2020 (edited) Oh, I think I have figured it out. I no longer get an error any more when I put Global $vNumber In the beginning of each of my functions Edited January 26, 2020 by adjist
Earthshine Posted January 26, 2020 Posted January 26, 2020 That sounds very wrong if it’s global it’s scope is global to the entire program and you shouldn’t have to declare it more than once My resources are limited. You must ask the right questions
adjist Posted January 26, 2020 Author Posted January 26, 2020 22 minutes ago, Earthshine said: That sounds very wrong if it’s global it’s scope is global to the entire program and you shouldn’t have to declare it more than once erm.. forget I said that here is what I said on another post, this is pretty much what I am wanting to do 19 minutes ago, adjist said: I see, So you're saying , set something such as ? Global $example = 0 At the top of my script, and inside the func I put ? Func example() $example = 1 ;code $example = 0 EndFunc But when I do this, I get this error, Variable used without being declared.
Subz Posted January 26, 2020 Posted January 26, 2020 You should post your entire code because the example above wouldn't give you an error. Global $example = 0 example() MsgBox(4096, "", "$example = " & $example) Func example() $example = 1 MsgBox(4096, "", "$example = " & $example) $example = 0 EndFunc
adjist Posted January 26, 2020 Author Posted January 26, 2020 wow. i had accidentally called my functions before declaring the global value everything works now I'm an idiot!
Earthshine Posted January 26, 2020 Posted January 26, 2020 That’s why I ask you to post your whole script so we could see what’s going on My resources are limited. You must ask the right questions
adjist Posted January 27, 2020 Author Posted January 27, 2020 Also, is there any way I could read the variable from a loop? Such as: Global $test = 0 yea() example() Func yea() While(1) $test = 1 ;code $test = 0 WEnd EndFunc func example() if $test = 1 Then ConsoleWrite("hello") EndIf EndFunc
jchd Posted January 27, 2020 Posted January 27, 2020 Didn't you try to run such a snippet? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
adjist Posted January 27, 2020 Author Posted January 27, 2020 1 minute ago, jchd said: Didn't you try to run such a snippet? Yes. I guess functions cannot update variables globally?
jchd Posted January 27, 2020 Posted January 27, 2020 Yes you can! RTFM and see that's precisely the purpose of Global. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
adjist Posted January 27, 2020 Author Posted January 27, 2020 1 minute ago, jchd said: Yes you can! RTFM and see that's precisely the purpose of Global. Sorry, I meant that I guess that functions cannot update variables while they are inside a loop
jchd Posted January 27, 2020 Posted January 27, 2020 Wrong guess again. What makes you believe that? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
adjist Posted January 27, 2020 Author Posted January 27, 2020 Just now, jchd said: Wrong guess again. What makes you believe that? Well, if I try to change a variable in a loop such as Func yea() While(1) $test = 1 ;code $test = 0 WEnd EndFunc and have an if statement (inside another function) such as func example() if $test = 1 Then ConsoleWrite("hello") EndIf EndFunc It won't print the message If there is a way to do it, could you be able to tell me how?
jchd Posted January 27, 2020 Posted January 27, 2020 1 minute ago, adjist said: It won't print the message No need to try to run the code, it's obvious the message can't be printed. Beside the fact that the present code will never exit the function yea() since it contains an infinite loop without exit route, you reset $test to 0 before invoking example(), so no wonder the msg never prints. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
jchd Posted January 27, 2020 Posted January 27, 2020 Runable code: Global $test = 0 yea() example() Func yea() Local $t = TimerInit() Do $test += 1 Until TimerDiff($t) > 1000 EndFunc func example() if $test > 0 Then ConsoleWrite("$test is now " & $test & @LF) EndIf EndFunc This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
adjist Posted January 27, 2020 Author Posted January 27, 2020 9 minutes ago, jchd said: Runable code: Global $test = 0 yea() example() Func yea() Local $t = TimerInit() Do $test += 1 Until TimerDiff($t) > 1000 EndFunc func example() if $test > 0 Then ConsoleWrite("$test is now " & $test & @LF) EndIf EndFunc I appreciate it!
Somerset Posted January 27, 2020 Posted January 27, 2020 2 hours ago, jchd said: Yes you can! RTFM and see that's precisely the purpose of Global. Autoit has a manual? What edition is it up to? Danp2 and FrancescoDiMuro 2
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