Sign in to follow this  
Followers 0
Baz

_FileWriteToLine

8 posts in this topic

Hi ya.

I have written a script that records the temperature and stores the information in a php file and also a txt file so that if the script is restarted, it reads the old values back from the txt file. I have removed most of the coding to keep it simple as I have one problem. The script fails to complete lines 76 ($err = _FileWriteToLine ( $file_txt, 3, $hvalue, 1 )) and 80 (FileWriteToLine ( $file_txt, 6, $lvalue, 1 )), even though lines 86 and 87 do the same but to a different file. I have put in an MSGBOX to display the value to see and it is correct. If anyone has got any ideas that would be great. I have added an error thing to line 86 and this comes back with "6" that would suggest that the value to be written is invalid but how can that be when it works with lines 86 and 87 and MSGBOX?

To test the script, you will need to have two files each with at least 20 blank lines, backup.txt and current_.php Once you start the file, after 5 seconds it will ask you for a value and if you give it say 30 you will see that within the backup.txt file the first two lines are correct but line 3 which should contain 30 is blank.

Anyway thanks for looking.

#include <File.au3>
#Include <Date.au3>
#include <Array.au3>
Dim $time, $lastdate, $today, $hour
Dim $file
Dim $buf
Dim $hdate;date of high value recorded
Dim $htime;time of high value recorded
Dim $ldate;date of low value recorded
Dim $ltime;time of low value recorded
Dim $hvalue;high value
Dim $lvalue =99

$file_php = "Current_.php"
$file_txt = "backup.txt"

$lastdate = _NowDate()
$date = _NowDate()
$date = StringReplace ( $date, "/", "-" )

$list = FileReadLine ( $file_txt, 1 )
$hour = FileReadLine ( $file_txt, 2 )
$hvalue = FileReadLine ( $file_txt, 3 )
$hdate = FileReadLine ( $file_txt, 4 )
$htime = FileReadLine ( $file_txt, 5 )
$lvalue = FileReadLine ( $file_txt, 6 )
$ldate = FileReadLine ( $file_txt, 7 )
$ltime = FileReadLine ( $file_txt, 8 )
    
Wait()
    
While 1
        Action()
WEnd

Func Action()
        $buf = InputBox ( "New Value", "Please enter a new value" )
        _Showval($buf)  
    Sleep ( 120000 );sleep for two minutes to stop the process from running more then once on the hour.
    Wait()
EndFunc

Func Wait() 
    Sleep ( 5000 )
EndFunc

Func _Showval($tempval)
    $value = Number($buf)
    If $value >= $hvalue Then
        $hvalue = $value
        $hdate = _NowDate()
        $htime = _NowTime() 
    EndIf
    If $value <= $lvalue Then
        $lvalue = $value
        $ldate = _NowDate()
        $ltime = _NowTime() 
    EndIf
        
    $today = _NowDate()
    If $today = $lastdate Then;Check to see if we should start fresh counters as we only record one days worth of data
    Else
        $list = ""
        $hour = ""
        _FileWriteToLine ( $file_php, 37, " ", 1 );Go back to using one graph
    EndIf
    If $list = "" Then 
        $list = $buf
        $hour = @HOUR & "00"
    Else
        $list = $list & "," & $buf
        $hour = $hour & "," & @HOUR & "00"
    EndIf
    _FileWriteToLine ( $file_txt, 1, $list, 1 )
    _FileWriteToLine ( $file_txt, 2, $hour, 1 )
    $err = _FileWriteToLine ( $file_txt, 3, $hvalue, 1 )
    If @error Then MsgBox(0,"error",@error)
    _FileWriteToLine ( $file_txt, 4, $hdate, 1 )
    _FileWriteToLine ( $file_txt, 5, $htime, 1 )
    _FileWriteToLine ( $file_txt, 6, $lvalue, 1 )
    _FileWriteToLine ( $file_txt, 7, $ldate, 1 )
    _FileWriteToLine ( $file_txt, 8, $ltime, 1 )
    _FileWriteToLine ( $file_php, 14, "$graph->values       =   '" & $list & "';", 1 )
    _FileWriteToLine ( $file_php, 15, "$graph->labels       =   '" & $hour & "';", 1 )
    _FileWriteToLine ( $file_php, 3, "  The last recording was " & $buf & " on " & $date & " at " & _NowTime () , 1 )
    _FileWriteToLine ( $file_php, 5, "  The highest recording was " & $hvalue & " on " & $hdate & " at " & $htime , 1 )
    _FileWriteToLine ( $file_php, 7, "  The lowest recording was " & $lvalue & " on " & $ldate & " at " & $ltime , 1 )
    If @HOUR >= "12" Then
        _FileWriteToLine ( $file_php, 37, "$graph->charts       =   2;", 1 );If it is 12pm, then start a second graph
    Else
        _FileWriteToLine ( $file_php, 37, " ", 1 )  
    EndIf   
    $lastdate = _NowDate()
EndFunc  ;==>_ShowTemp

Share this post


Link to post
Share on other sites



use iniwrite and iniread so you can use sections and keys which is very useful

Share this post


Link to post
Share on other sites

use iniwrite and iniread so you can use sections and keys which is very useful

Fair comment, but this should work and I would like to know why it doesn't work. I hate to have to work around problems but thanks.

Cheers

Baz

Share this post


Link to post
Share on other sites

Fair comment, but this should work and I would like to know why it doesn't work. I hate to have to work around problems but thanks.

Cheers

Baz

sure no problem

i never liked filewrite, but iniwrite is very nice once said a wise man.

Share this post


Link to post
Share on other sites

Iniwrite and Iniread...is really much better than writing to a .txt. simpler...and has less errors...hope this helped you.

Share this post


Link to post
Share on other sites

Hi all.

Ok, changed the code to use read/writeINI and it works great. So with your help I can move on but now I need to know why I had the issue that I had, just the way I am.

Thank you very much for your help.

Cheers

Baz

Share this post


Link to post
Share on other sites

Well...I Really Cant Say. The File Write Might Be Buggy? Ive Never Used It, Ive Always Used IniWrite(), IniRead()

So Many Its Buggy?/Broken? :)

Share this post


Link to post
Share on other sites

Well...I Really Cant Say. The File Write Might Be Buggy? Ive Never Used It, Ive Always Used IniWrite(), IniRead()

So Many Its Buggy?/Broken? :)

INI's have a 32KB limit on them.

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