Jump to content

How to read file and compare number value


 Share

Recommended Posts

exapmple from autoit help ..

 

Local $file = FileOpen("test.txt", 0)

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

; Read in 1 character at a time until the EOF is reached
While 1
    Local $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Char read:", $chars)
WEnd

FileClose($file)

you could as well use it like this:

Local $file = FileOpen("test.txt", 0)

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

    Local $text = FileRead($file)
    MsgBox(0, "Full Text:", $chars)


FileClose($file)

if "fileread" doesn't suit your neads you could take a look at 

FileReadLine ( "filehandle/filename" [, line] )

 

in this case 

Local $line = FileReadLine($file)
       MsgBox(0, "Line read:", $line)
       
       
;load line 3
Local $line = FileReadLine($file,3)
       MsgBox(0, "Line 3 contains:", $line)

 

good luck!

Link to comment
Share on other sites

  • Developers

So you want to compare some values in these xml files in particular fields  not just a value in a file. :) 
Why not start with properly explaining what you want to accomplish and what you have tried so far?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

As you don't specify the values to be checked here is a random try  :)

_Compare("sample1.txt", "sample2.txt", "G_RFTX_F2")

Func _Compare($file1, $file2, $test)
    $txt1 = FileRead($file1)
    $txt2 = FileRead($file2)
    $value_1 = StringRegExpReplace($txt1, '(?s).*' & $test & '.*?ValNum="([\d.]+).*', "$1")
    $value_2 = StringRegExpReplace($txt2, '(?s).*' & $test & '.*?ValNum="([\d.]+).*', "$1")
    Msgbox(0,"", $test & " values are :" & @crlf & @crlf & _ 
        $value_1 & "   in " & $file1 & @crlf & _ 
        $value_2 & "   in " & $file2)
EndFunc


#cs
$txt1 = FileRead("sample1.txt")
$txt2 = FileRead("sample2.txt")
$test = "G_RFTX_F1"

$G_RFTX_F1_1 = StringRegExpReplace($txt1, '(?s).*' & $test & '.*?ValNum="([\d.]+).*', "$1")
$G_RFTX_F1_2 = StringRegExpReplace($txt2, '(?s).*' & $test & '.*?ValNum="([\d.]+).*', "$1")

Msgbox(0,"", $test & " are :" & @crlf & @crlf & _ 
    $G_RFTX_F1_1 & " (sample1)" & @crlf & _ 
    $G_RFTX_F1_2 & " (sample2)")
#ce

 

Link to comment
Share on other sites

  • 2 weeks later...

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...