Jump to content

FileReadLine and process from two files.


Kryten68
 Share

Recommended Posts

Hi,

I'm trying to put a script together to automate same data input to a 3rd party GUI.

My data exists as line separated variables in two .txt files (tns.txt and dns.txt).

I need to read the first line from tns.txt and send it, then do stuff. Then send the 1st

line from dns.txt and do a bit more. Then repeat with line two from each file, and so on.

Here is what i have so far:-

Sleep(5000) ; Just to give me time to activate the 3rd party GUI.

$tn = FileOpen("D:\posh\tns.txt", 0) ; Open first file

$dn = FileOpen("D:\posh\dns.txt", 0) ; Open second file

; Read in lines of text until the EOF is reached

While 1 ; Begin LOOP

$tn = FileReadLine($tn) ; Read first tn value

$dn = FileReadLine($dn) ; Read first dn value

If @error = -1 Then ExitLoop ; test for error condition

Send($tn) ; send first tn value

Send("{enter}") ; send an enter key press

Send($dn) ; send the dn value

Send("{enter}") ; send an enter key press

Sleep(500) ; wait half a sec

WEnd ; repeat until ...

This is a simplified example of what I'm struggling with. If this would work then my bigger script will work too.

This example reads the first values and sends them just fine but just sends enter key presses for the other values.

It also seems to damage my tns.txt and dns.txt file too, filling them with return presses?

Any guidance much appreciated!

Thanks,

Stuart

FileClose($dn)

FileClose($tn)

Link to comment
Share on other sites

Example:

Run("notepad.exe", @WindowsDir)
WinWait("[Class:Notepad]") ;Just to give me time to activate the 3rd party GUI.
$hNotepad = WinGetHandle("[Class:Notepad]")

$readTNS = FileRead("D:\posh\tns.txt")
$readDNS = FileRead("D:\posh\dns.txt")

$tn = StringSplit(StringStripCR($readTNS), @LF)
$dn = StringSplit(StringStripCR($readDNS), @LF)

$Result = ""

For $i = 1 To $tn[0]
    If (UBound($dn) - 1) >= $i Then
        $Result &= $tn[$i] & @CRLF & $dn[$i] & @CRLF
    Else
        $Result &= $tn[$i] & @CRLF
    EndIf
Next

ControlSetText($hNotepad, "", "Edit1", $Result)
Link to comment
Share on other sites

$tn = FileOpen("D:\posh\tns.txt", 0)    ; Open first file
$dn = FileOpen("D:\posh\dns.txt", 0)  ; Open second file
                                                       ; Read in lines of text until the EOF is reached
While 1                                          ; Begin LOOP
    $tn = FileReadLine($tn)           ; Read first tn value
    $dn = FileReadLine($dn)          ; Read first dn value
        .
        .
        .
WEnd                                                 ; repeat until ...

Look at what you are doing. You create two file handles, $tn and $dn, then also use them as variables when you read from them.

Once you read data into those variables you overwrite your file handles. Subsequent reads will fail or yield unpredictable results.

Use different variables:

$tn_record = FileReadLine($tn)

$dn_record = FileReadLine($dn)

-Barry.

Edited by bstjohn
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...