Jump to content

Recommended Posts

Posted (edited)

hello to all,

need help to understand _FileWriteToLine.

Use to build HTML page, all work fine until i want to use variable in line to write.

Write small code to explain better my problem:

- create file

- random number

- write to first line

- msgbox to user

- udf read first value and assign to variable

- _FileWriteToLine overwrite first line with modified value

#include <file.au3>

global $RESULT 

;////////////////////////////////////////////////////////////////////
;   create text file with random value in first line
;////////////////////////////////////////////////////////////////////
    $FILE = FileOpen(@ScriptDir & "\Metric_value.txt",10)
    sleep(1000)
    FileWrite($file, string(Random(10000, 99999, 1)))
    FileClose($FILE)


;////////////////////////////////////////////////////////////////////
;   function read from above random generated text file 
;   and return value into variable
;////////////////////////////////////////////////////////////////////
    _ret_metric_value()
    msgbox(0,"",$RESULT)

;////////////////////////////////////////////////////////////////////
;   doesn't work - replace 1st line in file with modified value (add some test text)
;////////////////////////////////////////////////////////////////////
    _FileWriteToLine((@ScriptDir & "\Metric_value.txt", 1, "->> " & $RESULT & " <<-", 1)


;////////////////////////////////////////////////////////////////////
;   find metric value after compare images
;////////////////////////////////////////////////////////////////////
Func _ret_metric_value()
    $FILE = FileOpen(@ScriptDir & "\Metric_value.txt",0)
    $RESULT = FileRead($FILE)
    FileClose($FILE)
    Return $RESULT
EndFunc

i must use my UDF _ret_metric_value() because this file in my production,

store value generated from DOS command (numeric delta value from image differences process)

what is wrong ?

thank you,

m.

___ EDIT

modify script because find an error, now works, but can't replicate my production problem...

Edited by myspacee
Posted

hello to all,

need help to understand _FileWriteToLine.

Use to build HTML page, all work fine until i want to use variable in line to write.

Write small code to explain better my problem:

- create file

- random number

- write to first line

- msgbox to user

- udf read first value and assign to variable

- _FileWriteToLine overwrite first line with modified value

#include <file.au3>

global $RESULT 

;////////////////////////////////////////////////////////////////////
;   create text file with random value in first line
;////////////////////////////////////////////////////////////////////
    $FILE = FileOpen(@ScriptDir & "\Metric_value.txt",10)
    sleep(1000)
    FileWrite($file, string(Random(10000, 99999, 1)))
    FileClose($FILE)


;////////////////////////////////////////////////////////////////////
;   function read from above random generated text file 
;   and return value into variable
;////////////////////////////////////////////////////////////////////
    _ret_metric_value()
    msgbox(0,"",$RESULT)

;////////////////////////////////////////////////////////////////////
;   doesn't work - replace 1st line in file with modified value (add some test text)
;////////////////////////////////////////////////////////////////////
    _FileWriteToLine((@ScriptDir & "\Metric_value.txt", 1, "->> " & $RESULT & " <<-", 1)


;////////////////////////////////////////////////////////////////////
;   find metric value after compare images
;////////////////////////////////////////////////////////////////////
Func _ret_metric_value()
    $FILE = FileOpen(@ScriptDir & "\Metric_value.txt",0)
    $RESULT = FileRead($FILE)
    FileClose($FILE)
    Return $RESULT
EndFunc

i must use my UDF _ret_metric_value() because this file in my production,

store value generated from DOS command (numeric delta value from image differences process)

what is wrong ?

thank you,

m.

___ EDIT

modify script because find an error, now works, but can't replicate my production problem...

Works fine if you take out the stray open paren in _FileWriteToLine():
#include <file.au3>

Global $RESULT, $FILE

$FILE = FileOpen(@ScriptDir & "\Metric_value.txt", 10)
Sleep(1000)
FileWrite($FILE, String(Random(10000, 99999, 1)))
FileClose($FILE)

_ret_metric_value()
MsgBox(0, "", $RESULT)

_FileWriteToLine(@ScriptDir & "\Metric_value.txt", 1, "->> " & $RESULT & " <<-", 1)

_ret_metric_value()
MsgBox(0, "", $RESULT)

Func _ret_metric_value()
    $FILE = FileOpen(@ScriptDir & "\Metric_value.txt", 0)
    $RESULT = FileRead($FILE)
    FileClose($FILE)
    Return $RESULT
EndFunc  ;==>_ret_metric_value

So what's the new problem...?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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
×
×
  • Create New...