AutoitMike Posted April 28, 2022 Share Posted April 28, 2022 I have a need to create a number of variables like $Var_1, $_var2, ........$_VarN The Assign function looks really good EXCEPT that if you try and USE any of the variables it creates, an exception is created: "Warning: $_Var1: possibly used before declaration." "ERROR: $_Var1: undeclared global variable" Of course, if I declare them all, no problem. I just am trying to refactor my code to eliminate as many lines of code as possible. If I declare them all, I have already CREATED them. Is there any other way to dynamically create variables? Link to comment Share on other sites More sharing options...
Nine Posted April 29, 2022 Share Posted April 29, 2022 Disable au3check. Then good luck to you. You should really rethink your approach. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Earthshine Posted April 29, 2022 Share Posted April 29, 2022 I don’t understand the concern with re-factoring a code and not declaring variables. Why do the number of lines of code even matter? My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Developers Jos Posted April 29, 2022 Developers Share Posted April 29, 2022 9 hours ago, AutoitMike said: Is there any other way to dynamically create variables? Simply use an Array. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
HurleyShanabarger Posted April 29, 2022 Share Posted April 29, 2022 Use Eval: #include <MsgBoxConstants.au3> Example() Func Example() ; Assign the variable string sString with data. Assign("sString", "This is a string which is declared using the function Assign") ; Find the value of the variable string sString and assign to the variable $sEvalString. Local $sEvalString = Eval("sString") ; Display the value of $sEvalString. This should be the same value as $sString. MsgBox($MB_SYSTEMMODAL, "", $sEvalString) EndFunc ;==>Example Link to comment Share on other sites More sharing options...
jchd Posted April 29, 2022 Share Posted April 29, 2022 The question remains: why play useless games with Assign & Eval in the first place? 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) Link to comment Share on other sites More sharing options...
AutoitMike Posted April 29, 2022 Author Share Posted April 29, 2022 Hurley, Thanks for the suggestion. BTW I dont have <MsgBoxConstants.au3> I get an error about variable not yet defined on $MB_SYSTEMMODAL Maybe because I dont have the message box constants. Is this file available on Autoit web site? I will answer jchd's question here: jc, Usually, in a large program, hundreds of lines of code, it gets hard to manage it. One good example to eliminate code (called refactoring) is when dozens of variables need to be created and assigned a value. say I need to create 50 variables named $Lable_1 through $Label_55. This is what it would look like: $Lable_1="ABC" $Label_2="DEF" $Label_3="GHI" . . . . . All the way to : $Lable_55="ZZZ" ;Or what ever Maybe not simpler but more CONCISE: ;Three lines of code For $N=1 to 55 Assign("Lable_" & $N, {the value needed}) ;here you would pull the value from an array that you created containing the value needed (well, one more line ;of code) Next Link to comment Share on other sites More sharing options...
jchd Posted April 29, 2022 Share Posted April 29, 2022 Then make your array 2D and store the controlID (useless for labels in most use cases) and the text. Or better yet, use a Map. I've yet to see real-world code where Assign() is required or even useful. Earthshine 1 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) Link to comment Share on other sites More sharing options...
jchd Posted April 29, 2022 Share Posted April 29, 2022 BTW, the MsgBoxConstants.au3 UDF is part of the standard AutoIt install. Simply reinstall the latest version over your setup and you'll be on track. 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) Link to comment Share on other sites More sharing options...
Earthshine Posted April 30, 2022 Share Posted April 30, 2022 Refactoring had nothing to do with not declaring variables. Just don’t create ones that you’re not using My resources are limited. You must ask the right questions 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