Jump to content

Help with numbers


Recommended Posts

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 by Exhalt
Link to comment
Share on other sites

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 by 99ojo
Link to comment
Share on other sites

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

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 by Exhalt
Link to comment
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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

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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 by Exhalt
Link to comment
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...