Jump to content

FileRead problem


Recommended Posts

Hi everyone, i am new to files, so what i want to do here is open a file, write a number, reads it. But msg box shows nothing when i use filereadline(), or fileread(), any idea how to fix this or make this work?

Thanks in advance.

#NoTrayIcon
#include<file.au3>
Global $i=0
If FileExists(@ScriptDir&"\Screenshots\data\data.dat")=0 Then
DirCreate(@ScriptDir&"\Screenshots\data")
_FileCreate(@ScriptDir&"\Screenshots\data\data.dat")
EndIf
$File=FileOpen(@ScriptDir&"\Screenshots\data\data.dat",2)
FileWrite($File,$i)
$Read=FileReadLine($File,1)
MsgBox(64,"",$Read)
Edited by Generator
Link to comment
Share on other sites

  • Moderators

You have to "FileClose" before "FileRead" since you used "FileOpen"

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi everyone, i am new to files, so what i want to do here is open a file, write a number, reads it. But msg box shows nothing when i use filereadline(), or fileread(), any idea how to fix this or make this work?

Thanks in advance.

#NoTrayIcon
#include<file.au3>
Global $i=0
If FileExists(@ScriptDir&"\Screenshots\data\data.dat")=0 Then
DirCreate(@ScriptDir&"\Screenshots\data")
_FileCreate(@ScriptDir&"\Screenshots\data\data.dat")
EndIf
$File=FileOpen(@ScriptDir&"\Screenshots\data\data.dat",2)
FileWrite($File,$i)
$Read=FileReadLine($File,1)
MsgBox(64,"",$Read)
 oÝ÷ Ûú®¢×¢êܡע²÷«Ê)íz·¬¶)à!ü¨¹Ú'ßÛaj÷~)^¶§r·µè­!ü¨¹Ú!j÷­çâç«jÇX­±Ê'µéí³bê)zx§+_¢¼+اy¦¶¬Â¥u·¦¹Èf¢·}øéíjëh×6#NoTrayIcon
Global $i=0
Global $s_FileName = @ScriptDir & "\Screenshots\data\data.dat"
$File=FileOpen($s_FileName,10);Open for writing erasing previous contents and create directory struct if doesn't exist
FileWrite($File,$i)
FileClose($File)

$Read=FileReadLine($s_FileName,1)
MsgBox(64,"",$Read)
I highly recommend you don't do it this second way if you don't understand exactly what is going on. If you do it wrong, an error in an original function could throw the other functions off causing a massive autoit hard crash.

- The Kandie Man ;-)

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

  • Moderators

Thanks for all the helps guys. Especially The Kandie Man.

That's kind of funny... pseudo code versus telling you what your actual issue is... ahh well ... good one TKM

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

That's kind of funny... pseudo code versus telling you what your actual issue is... ahh well ... good one TKM

Lol no worries, one thing i discovered is i never know func can be used this way.

Ex:

FileClose(FileWrite(FileOpen($s_FileName,10),$i))

Thank you too SmOke_N

Link to comment
Share on other sites

  • Moderators

FileClose(FileWrite(FileOpen($s_FileName,10),$i))

Actually, TKM and I were talking about that before he posted it in MSN. We both had the conclusion since you couldn't get "proper" error handling out of it, that it would probably be better not to show you that you could do that.... guess he changed his mind.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Lol no worries, one thing i discovered is i never know func can be used this way.

Ex:

FileClose(FileWrite(FileOpen($s_FileName,10),$i))

Thank you too SmOke_N

I actually picked up the multiple file functions on one line from Smoke_N.

- The Kandie Man ;-)

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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