Sign in to follow this  
Followers 0
shaded

searching and reading txt lines

3 posts in this topic

#1 ·  Posted (edited)

I am new to autoIt please help if possible,

I have a bot that reading poker cards it uses checksum value and card numbers.Every checksum match with a card value.

I want the bot to read a txt file which include checksum value and card value in everyline like this;

(Checksum,card)

(873175,A)

(6707434,2)

i want bot to search for the checksum value it gets from the card on the screen and search the txt line by line. If it find the value of checksum it will find the card value.Is it possible? I read some topics about reading line and search.I also read creating dictionary but it is very hard for me to learn now.

I examine some examples FileReadToArray() for finding the checksum value in a file and FileReadLine() for reading lines with checksum and card values

Am i on the right way or not? Can someone give an example for finding my way on the issue.

Edited by shaded

Share this post


Link to post
Share on other sites



$Checksumcard = IniRead(@Desktopdir & "\file.ini", "Checksumcard", 873175, '*')

While your ini file would read thus

[Checksumcard]

873175=A

6707434=2

Would result in $Checksumcard holding the value "A"

I think


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

It depends on what you are trying to return if the file is written exactly the way you show it. That is a a flat text file

To get everything between the "(" and ")" for all lines as an array then

$sStr = FileRead(@ScriptDir & "\somefile.txt")
$aRtn = _RtnVal()
If NOT @Error Then
    ;; Do whatever you want here
EndIf
Func _RtnVal()
    $aRegExp  = StringRegExp($sStr, "(?m:^)\((\d+,.+)\)", 3)
    If NOT @Error Then Return $aRegExp
    Return SetError(1)
EndFunc

If you want to include the "(" and ")" in the return then use

$sStr = FileRead(@ScriptDir & "\somefile.txt")
$aRtn = _RtnVal()
If NOT @Error Then
    ;; Do whatever you want here
EndIf
Func _RtnVal()
    $aRegExp  = StringRegExp($sStr, "(?m:^)(\(\d+,.+\))", 3)
    If NOT @Error Then Return $aRegExp
    Return SetError(1)
EndFunc

If you only want the card portion of a particular line then

$sStr = FileRead(@ScriptDir & "\somefile.txt")
$iRtn = _RtnVal(873175);; using your first example
If NOT @Error Then
    ;; Do whatever you want here
EndIf
Func _RtnVal($iChecksum)
    $aRegExp  = StringRegExp($sStr, "(?m:^)(\" & $iChecksum & ",(.+)\)", 1)
    If NOT @Error Then Return $aRegExp[0]
    Return SetError(1)
EndFunc

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!"

Share this post


Link to post
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
Sign in to follow this  
Followers 0