Pottery Posted May 4, 2010 Share Posted May 4, 2010 (edited) Hey, I'm sure there is a way to do this but I don't even know what to call it to search it lol $k1 = FileReadLine("cdkeys.txt", 1) $k2 = FileReadLine("cdkeys.txt", 2) $k3 = FileReadLine("cdkeys.txt", 3) As you can see it reads my cdkeys for a program I have, how would I set it up so I dont have to type each seperate number, for example: $k[number] = FileReadLine("cdkeys.txt", [number]) And the [number]s would be the same so in my script I can go If $cdkey = $k1 Then And it would make $k[number] 1 while also making "cdkeys", [number] 1 Thanks for any help in advance, Exhalt. Edited May 4, 2010 by Exhalt Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 4, 2010 Share Posted May 4, 2010 You want an array. There's an excellent tutorial in the wiki HERE: .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...
Pottery Posted May 4, 2010 Author Share Posted May 4, 2010 I still don't understand, I looked at that before I posted. Link to comment Share on other sites More sharing options...
GodlessSinner Posted May 4, 2010 Share Posted May 4, 2010 (edited) Global $line[2] ; 2 - is a size of array(started from 0, so it is 3) For $i = 0 to 2 Step 1 $line[$i] = FileReadLine("cdkeys.txt", $i) Next For $i = 0 to 2 Step 1 MsgBox(0, "", $line[$i]) Next Edited May 4, 2010 by GodlessSinner _____________________________________________________________________________ Link to comment Share on other sites More sharing options...
99ojo Posted May 4, 2010 Share Posted May 4, 2010 (edited) Hi, Variable solution: #include <file.au3> $file = FileOpen ("cdkeys.txt", 0) For $i = 1 To _FileCountLines ("cdkeys.txt") Assign ("k" & $i, FileReadLine ($file, $i)) Next FileClose ($file) For $i = 1 To _FileCountLines ("cdkeys.txt") ConsoleWrite (Eval ("k" & $i) & @CRLF) Next Array solution: #include <file.au3> Dim $line [_FileCountLines ("cdkeys.txt") + 1] For $i = 1 To _FileCountLines ("cdkeys.txt") $line [$i] = FileReadLine ($file, $i) Next For $i = 1 To UBound ($line) -1 ConsoleWrite ($line [$i] & @CRLF) Next Edited May 4, 2010 by 99ojo Link to comment Share on other sites More sharing options...
wraithdu Posted May 4, 2010 Share Posted May 4, 2010 (edited) Arrays are a better solution, but literally what the OP asked for: For $i = 1 to 5 Assign("k" & $i, FileReadLine("cdkeys.txt", $i)) Next For $i = 1 to 5 ConsoleWrite("k" & $i & " is: " & Eval("k" & $i)) Next Edited May 4, 2010 by wraithdu Link to comment Share on other sites More sharing options...
Fulano Posted May 4, 2010 Share Posted May 4, 2010 Just a side note: From the manual:From a performance standpoint it is a bad idea to read line by line specifying "line" parameter whose value is incrementing by one. This forces AutoIt to reread the file from the beginning until it reach the specified line. So perhaps this would be better: (borrowing wrathdu's version):$file = FileOpen ("cdkeys.txt") FileReadLine ($file); eat the first line, as it appears to be skipped above For $i = 1 to 5 Assign("k" & $i, FileReadLine($file)) Next FileClose($file) For $i = 1 to 5 ConsoleWrite("k" & $i & " is: " & Eval("k" & $i)) Next #fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja! Link to comment Share on other sites More sharing options...
99ojo Posted May 4, 2010 Share Posted May 4, 2010 @Fulano: Banging my head on the desk, you are right. ;-)) Stefan P.S: To much looking at the code from @Exhalt and not looking beyond the horizon..... Link to comment Share on other sites More sharing options...
Pottery Posted May 5, 2010 Author Share Posted May 5, 2010 Thanks a bunch to all of you! Link to comment Share on other sites More sharing options...
Pottery Posted May 5, 2010 Author Share Posted May 5, 2010 (edited) Ok I used the script provided by Fulano: $file = FileOpen ("cdkeys.txt", 0) FileReadLine ($file); eat the first line, as it appears to be skipped above For $i = 1 to 5 Assign("k" & $i, FileReadLine($file)) Next FileClose($file) For $i = 1 to 5 ConsoleWrite("k" & $i & " is: " & Eval("k" & $i)) Next And I would use it like this, right? If $Input1 = $k4 Then I'm getting undeclared variable so I have to have something wrong here.. Edited May 5, 2010 by Exhalt Link to comment Share on other sites More sharing options...
Pottery Posted May 5, 2010 Author Share Posted May 5, 2010 I did MsgBox(0, "", Eval("k" & 3)) And it came out with the right key, so how would I use that with If $Input1 = $k3 Then ? Link to comment Share on other sites More sharing options...
jchd Posted May 5, 2010 Share Posted May 5, 2010 Guys, you're really making this overcomplicated! #Include <Array.au3> Local $k _FileReadToArray("cdkeys.txt", $k) ; you may have to remove or ignore the first element if the first line doesn't hold sensible data ; in which case, make it For $i = 2 .... For $i = 1 to UBound($k) - 1 ConsoleWrite("k" & $i & " is: " & $k[$i]) Next ; or, much simpler: _ArrayDisplay($k) 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...
Pottery Posted May 5, 2010 Author Share Posted May 5, 2010 Ooooohhh, ok that made it easier to understand. It works with what I want it to do, though is there anyway to do something like.. If $Input1 = $k[$i] Then I have like 24 items that need keys so I was thinking I would have like cdkeys_itemname.txt, and so on; I'll figure that out myself I'm just wondering if it's possible to ask for lines 1-100 or just any line in that file, if you understand what I mean. Link to comment Share on other sites More sharing options...
jchd Posted May 5, 2010 Share Posted May 5, 2010 I've no idea about the actual contents of your input file, so it's a bit difficult for me to offer guidance wrt filtering what's being loaded this way. I'd say that given the small size of your file (personal crystal ball assumption) you can ignore X first entries in the array (or remove them to keep your numbering scheme consistent) and ReDim the array to trim the tail you don't need. Look at all array and _Array functions to find what suits your actual needs. 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...
Pottery Posted May 5, 2010 Author Share Posted May 5, 2010 cdkeys.txt is just a notepad file and it contains 1000 cdkeys each on a different line Link to comment Share on other sites More sharing options...
jchd Posted May 5, 2010 Share Posted May 5, 2010 Then I don't see what you really need: I have like 24 items that need keys so I was thinking I would have like cdkeys_itemname.txt, and so on; I'll figure that out myself I'm just wondering if it's possible to ask for lines 1-100 or just any line in that file The baby is small, you can load it into memory, no question. Then you pick what you need inside it, using indexing in the array. If you need to sort out keys for various products, you have to provide the information linking, say, key $k[17] with product "Microsoft Office 2043 Enterprise Edition". Is that what you mean? If yes, how is that link currently materialized? 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...
Pottery Posted May 5, 2010 Author Share Posted May 5, 2010 (edited) I think you have the wrong idea of what I mean, these aren't actual cdkeys or anything.. they're cdkeys that are going to be used for products. When people buy a product, they get a cdkey. Then they type in that cdkey into the downloader and if it's a valid cdkey from one of the lines in cdkey.txt, it downloads the file. I have the whole program written already, I just need to sort out this problem with the cdkey reading. Like lines 1 to 300 are for 1 product. Edited May 5, 2010 by Exhalt Link to comment Share on other sites More sharing options...
jchd Posted May 5, 2010 Share Posted May 5, 2010 That's exactly what I thought: your cdkeys are product keys. OK but how do you know that lines 1..300 correspond to product #1? I believe you'd have better time using a .INI file structure: [product 1] <product key ABCD_1234>= whatever you like, or nothing <product key ABCD_1235>= whatever you like, or nothing <product key ABCD_1236>= whatever you like, or nothing [product 2] <product key EFGH_5678>= whatever you like, or nothing <product key EFGH_5679>= whatever you like, or nothing <product key EFGH_5680>= whatever you like, or nothing There are functions to read/query/write such structure easily. 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...
Pottery Posted May 5, 2010 Author Share Posted May 5, 2010 I know that they correspond to product #1 because it's my product :S, is there an easier way than to type that in 1000 times? Link to comment Share on other sites More sharing options...
jchd Posted May 5, 2010 Share Posted May 5, 2010 I really don't get you. Anyway, if you simply want to check that a given key is valid (= found somewhere in you cdkeys.txt file) then why not making it dumb simple? $s = FileRead("cdkeys.txt") $found = StringInStr($s, $key) If $found Then ... 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...
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