cueclub Posted April 4, 2010 Share Posted April 4, 2010 (edited) ok real quick question, and perhaps my vocabulary is a little off so please hold your laughter. Here is my question: I am building a math program for my son. Pretty easy I think. But for the locals I have there are many. At one point 560 is there an easier way to add the locals without typing them all out? ie: local $a1p1, $a2p1, $a3p1 ect ect......... thanks Cue Edited September 5, 2010 by cueclub Link to comment Share on other sites More sharing options...
JohnOne Posted April 4, 2010 Share Posted April 4, 2010 (edited) Well you could make a code to type it for you, something similar to this For $i = 1 To 360 ConsoleWrite("local $a1p" & $i & @CRLF) Next Or in the same format you show above, take your pick. EDIT: sorry For $i = 1 To 360 ConsoleWrite("local $a" & $i & "p" & @CRLF) Next But your best option by far is to use an array. Edited April 4, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
GEOSoft Posted April 4, 2010 Share Posted April 4, 2010 Take a look at Assign() in the help file but I doubt that it will work well for you. It's easy to create the variables with this code but assigning a value will be a different story. For $i = 1 To 600 Assign("a" & $i & "p1", "", 1);; This creates $a1p1 through $a600p1 in local scope Next Also when you want to read an assigned variable it's best to use Eval(). Best suggestion: Start typing and you don't need separate lines for the variables remember. You can use Local $a1p1 = 1, $a2p1 = 2, $a3p1 = 3, ;; and on and on George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
darkjohn20 Posted April 4, 2010 Share Posted April 4, 2010 (edited) Why not use an array? Local $Array[560] Or, better yet, $MaxA = 50 $MaxP = 50 Local $Array[$A][$P] ;a0-49, p0-49 So you could do: $Array[5][10] instead of $a5p10. Edited April 4, 2010 by darkjohn20 Link to comment Share on other sites More sharing options...
cueclub Posted April 4, 2010 Author Share Posted April 4, 2010 I have tried $p1a[560] but when i run the syntax check it throws an error to all individual $p1a items. if i remove 1 of these, would it make a difference? #Include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) I have used the local $array[***] before and had it work, but for some reason it is not on this one. also when I couldn't get it to work like that I changed them to $a1p1. hort for answer 1 page 1. and it goes through answer 56 - page 10. that's where the 560 is coming into play. so that's why I'm kinda lost. worst case is i type them all out thanks Cue Link to comment Share on other sites More sharing options...
GEOSoft Posted April 4, 2010 Share Posted April 4, 2010 Why not use an array? Local $Array[560] Or, better yet, $MaxA = 50 $MaxP = 50 Local $Array[$A][$P] ;a0-49, p0-49 So you could do: $Array[5][10] instead of $a5p10. I thought of an array too but that's going to end up being more typing than just declaring them. He could also use a combination of an array with the assign depending on how lazy he is. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
darkjohn20 Posted April 4, 2010 Share Posted April 4, 2010 I have tried $p1a[560] but when i run the syntax check it throws an error to all individual $p1a items. if i remove 1 of these, would it make a difference? #Include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) I have used the local $array[***] before and had it work, but for some reason it is not on this one. also when I couldn't get it to work like that I changed them to $a1p1. hort for answer 1 page 1. and it goes through answer 56 - page 10. that's where the 560 is coming into play. so that's why I'm kinda lost. worst case is i type them all out thanks Cue Post the code so I can see what you mean. Link to comment Share on other sites More sharing options...
cueclub Posted April 4, 2010 Author Share Posted April 4, 2010 #Include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Local $ini5 = @ScriptDir & "\answers.ini" & "Answer", $a1p1, $a2p1 $a1p1 = iniread($ini5, "1", "", $aTabBox) $a1p2 = iniread($ini5, "2", "", $aTabBox) and it will go like this all the way to 56 =\ I work on the code 1 part at a time. And if i cant get this part done then i wont continue. lol Link to comment Share on other sites More sharing options...
jchd Posted April 4, 2010 Share Posted April 4, 2010 (edited) I beg to differ: anything near 560 local variables is the indication of a horrible design.Let me explain: I can understand needing several arrays and individual variables, but local variables must remain manageable at a local level.If you ever need significantly more than a handful variables in a function, then you need to consider making your code more modular, devoting to lower-level functions some gory details.The same applies to global variables, to some lesser extent due to asynchronous functions (OnEvent, Hotkeys and friends). Global constants are separate guys, of course.Don't hesitate to pass variables to functions and use ByRef smartly. It's my [language-independant] opinion that one needs to eventually(*) sacrifice a small percentage of efficiency to code clarity and sound architecture. If the working solution retained reveals a bit CPU-bound somewhere, then it's always time to consider compromises, but only if that makes a human-perceptible difference (2% is not perceptible) or when time constraints impose it (a fairly rare case in a scripting language).(*) Remember that it isn't always the case that it's less efficient to call a number of functions with some parameters compared to a large number of less local variables in a massive piece of code. That remark doesn't apply much to AutoIt because it's an interpreted language, but it's true with many compiled languages. First, the compiler is almost invariably able to discover clever optimizations when locality dominates, and then the machine cache(s) work much better and have a better chance to streamline operations.Edit: @cueclub that's what arrays are for. Edited April 4, 2010 by jchd 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...
darkjohn20 Posted April 4, 2010 Share Posted April 4, 2010 Local $Array[560] For $A = 1 To 560 $Array[$A] = IniRead("File.ini", $A, "Key", "Default") Next Link to comment Share on other sites More sharing options...
cueclub Posted April 4, 2010 Author Share Posted April 4, 2010 ah ok I will try that, And jchd, thank you for your info. To the rest of you thanks for your input as well. This is still all new to me, and am really learning as I go . Thanks again Cue Link to comment Share on other sites More sharing options...
JohnOne Posted April 4, 2010 Share Posted April 4, 2010 There is just something niggling away, telling me there is some easier way for you to do this. Can you explain the nature of the math program, Im willing to bet you will be offered easier options. Are you using for instance, a diferent section for every key and value ? (it looks that way). Have you looked at IniReadSection(). AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ShawnW Posted April 5, 2010 Share Posted April 5, 2010 There is just something niggling away, telling me there is some easier way for you to do this.Can you explain the nature of the math program, Im willing to bet you will be offered easier options.Are you using for instance, a diferent section for every key and value ? (it looks that way).Have you looked at IniReadSection().Yeah I was gonna mention .ini files. I am assuming these are problems sort of like a flash card script. Why not put all the problems and solutions in a .ini file and read them from the program. That way you could add or change things without recompiling the code. Link to comment Share on other sites More sharing options...
cueclub Posted April 5, 2010 Author Share Posted April 5, 2010 Shawn I have actually decided to go that route. Seemed easier that way lol Thanks again to everyone who has helped. Cue 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