Jump to content
Sign in to follow this  
DarkBoost

FileReadLine -> wild card style

Recommended Posts

DarkBoost

I am stumped on this and hope someone can point me in the right direction.

I have a Text File (c:\example.txt) which has the following:-

[1] 1 Box - 4 Circles
[2]          1 Box - 4 Circles
[3]   1 Box - 4 Circles

[*] = Text Line | [Note:] Different level of spaces at the start

1. Having troubles locating Line 2

2. Having trouble changing Line 2 from 4 Circles to 5 Circles

Share this post


Link to post
Share on other sites
iHonda

can you post the script you have so far


A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites
DarkBoost

I do not have a script at the moment as I am not sure how to write this however with my current knowledge of AutoIt I would write it like this:-

$i = 0

While 1 <= 10
    $var = FileReadLine("c:\example.txt")

    If $var = "*4 Circles" Then
        FileWriteLine($var, "5 Circles")
    EndIf
    
    $i = $i + 1
WEnd

Please do not laugh too hard , I do not use AutoIt too often :-(

Share this post


Link to post
Share on other sites
iHonda

mk i can help with this ill write an example for you to see and post it in a sec.

ok one more question does it need to be a text file?? or could you use and ini file.. because writing to a line is kinda a pain...

Edited by Zmaster

A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites
DarkBoost

It needs to be a text file.

I have tried combinations like "[(?x)]1 Box - 4 Circles" and "[[:space:]]1 Box - 4 Circles" and "[[:blank:]]1 Box - 4 Circles" etc. but having troubles.

Even if I am able to acknowledge the correct line I am not sure how to modify just the number :-(

Edited by DarkBoost

Share this post


Link to post
Share on other sites
iHonda

i seem to be having issues with the wildcards but i got a script that works but not with wildcards i really doubt that the filereadline function allows wildcards maybe we can think of another way to do it

;--------------------;
;    By: Zmaster     ;
;....................;
#Include <File.au3>

;Variables
Local $line_2

While 1
    $line_2 = FileReadLine(@DesktopDir & "\example.txt", 2)
    If $line_2 = "             1 Box - 4 Circles" Then
        _FileWriteToLine(@DesktopDir & "\example.txt", 2, "             1 Box - 5 Circles", 1)
        MsgBox(0,"",$line_2)
    Else
        MsgBox(0, "", $line_2)
    EndIf
ExitLoop
WEnd
Edited by Zmaster

A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites
BrettF
DarkBoost

@Zmaster -> thank you for taking the time to write your example, it makes sense and i have it working.

Is there a way to wildcard any spaces at the start of text so it will skip any amount of spaces before the text on the line?

Share this post


Link to post
Share on other sites
BrettF
iHonda

Take a look at StringInStr.

Cheers,

Brett

ah genius! i didnt even think of that >< i feel silly now

StringInStr ( "string", "substring" [, casesense [, occurrence [, start [, count]]]] )

A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites
DarkBoost

Sorry guys & gals :)

I am not having much luck with this... what am I doing wrong?

I am playing around with the example of StringInStr but am unable to locate the word ring.

Writing to this is no problem now, thanks iHonda

While 1
    $line = FileReadLine(@DesktopDir & "\example.txt")
    $string = StringInStr($line, "ring")

    If $string = "ring" Then
        MsgBox(0, "Search result:", $string)
        ExitLoop
    EndIf
WEnd
Edited by DarkBoost

Share this post


Link to post
Share on other sites
BrettF

Hi,

Check this out. It has the option to be expanded by adding additional case statements.

$file = FileOpen(@ScriptDir & "\example.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file)
    Select
        Case @error = -1
            MsgBox (0, "Search Result", "End Of File was met")
            ExitLoop
        Case StringInStr($line, "ring")
            MsgBox (0, "Search Result", $line)
            ExitLoop
    EndSelect
WEnd

FileClose($file)

Cheers,

Brett

Share this post


Link to post
Share on other sites
DarkBoost

That works and makes sense. Thanks for taking the time to write this -> BrettF

Whilst on the subject I am trying to achieve something similar. I have created my first INI file which has a line eg. SN=1111-2222-3333-4444

and whilst it performs the Automated install of the application I would like it to enter this information however it is required in separate boxes.

I can do it manually as shown below, however the number will be different most times, hence the INI file.

WinWait("Test Script", "")
ControlClick("Test Script", "", "[CLASS:Edit; INSTANCE:1]","1111")
ControlClick("Test Script", "", "[CLASS:Edit; INSTANCE:2]","2222")
ControlClick("Test Script", "", "[CLASS:Edit; INSTANCE:3]","3333")
ControlClick("Test Script", "", "[CLASS:Edit; INSTANCE:4]","4444")

I can read the INI file ok using -> IniRead however would like to know how I can just read/input the first 4 digits and then the next 4 digits and so on.

As I am not sure of what function I will need to use I find it hard to get the answer from the Help File. Sorry guys :)

Edited by DarkBoost

Share this post


Link to post
Share on other sites
BrettF

What are you trying to install? There is a chance it could be done silently.

Good job on finding the INIFunctions.

Maybe something like this?

$sString = "923A-5928-8FJA-48SB"
$aSplit = StringSplit ($sString, "-")
For $i = 1 to $aSplit[0]
    MsgBox (0, "", $aSplit[$i])
    ControlSetText ("Title", "", "[Class:Edit; Instance:" & $i, $aSplit[$i])
Next

Also, take a look at ControlSend/ControlSetText.

Share this post


Link to post
Share on other sites
DarkBoost

Although I am not 100% sure what all this is doing, some new to me functions in there, however it works perfectly!

Edited by DarkBoost

Share this post


Link to post
Share on other sites
BrettF

Well glad to hear it!

Just continue to read the helpfile, and study examples to try see whats happening. Then you will be sure whats happening. :)

Cheers,

Brett

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  

×