jbennett Posted November 3, 2008 Share Posted November 3, 2008 Hi everyone, I seem to have a very strange problem with displaying some text in a msgbox that's within a .txt file. I can write to the file but cannot read from it. Does anyone know what I may be doing wrong?. Thanks #include <Date.au3> $file = FileOpen(@scriptdir & "\test.txt", 2) ;FileWrite($file, _WeekNumberISO()) $test=Fileread($file,1) msgbox (0,"TEST","",$test) FileClose($file) Link to comment Share on other sites More sharing options...
Developers Jos Posted November 3, 2008 Developers Share Posted November 3, 2008 You will have to close it first before reading it. 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 More sharing options...
jbennett Posted November 3, 2008 Author Share Posted November 3, 2008 Thanks but i've tried that and it doesn't work $test=Fileread(@scriptdir & "\test.txt") msgbox (0,"TEST","",$test) Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 3, 2008 Share Posted November 3, 2008 Thanks but i've tried that and it doesn't work $test=Fileread(@scriptdir & "\test.txt") msgbox (0,"TEST","",$test) You missed the point. You can't have it open for write and read at the same time. FileClose() the write, then FileRead(). 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 Link to comment Share on other sites More sharing options...
jbennett Posted November 3, 2008 Author Share Posted November 3, 2008 I'm confused. I thought the code I just posted is correct Link to comment Share on other sites More sharing options...
Developers Jos Posted November 3, 2008 Developers Share Posted November 3, 2008 Your filehandle will be gone after you close it and you need to open it for read or use the filename. #Tidy_Parameters=/rel 1 #include <Date.au3> $file = FileOpen(@ScriptDir & "\test.txt", 2) FileWrite($file, _WeekNumberISO()) FileClose($file) $test = FileRead(@ScriptDir & "\test.txt") MsgBox(0, "TEST", $test) 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 More sharing options...
jbennett Posted November 3, 2008 Author Share Posted November 3, 2008 (edited) Thanks, That works as a whole but as soon as I comment out the write bit it doesn't display anything in the msgbox #Tidy_Parameters=/rel 1 #include <Date.au3> ;$file = FileOpen(@ScriptDir & "\test.txt", 2) ;FileWrite($file, _WeekNumberISO()) ;FileClose($file) $test = FileRead(@ScriptDir & "\test.txt") MsgBox(0, "TEST", $test) Not sure why? thanks EDIT ---- Haha I know why, I didn't have any data in the .txt file. Thanks Edited November 3, 2008 by jbennett Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 3, 2008 Share Posted November 3, 2008 Thanks, That works as a whole but as soon as I comment out the write bit it doesn't display anything in the msgboxNot sure why?thanksEDIT----Haha I know why, I didn't have any data in the .txt file.ThanksTo quote the sage philosopher Homer: Doh! 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 Link to comment Share on other sites More sharing options...
jbennett Posted November 3, 2008 Author Share Posted November 3, 2008 Haha I have one final question to get this fully working. Is it possible to write data to a hidden text file?. I don't really want to remove the hidden attribute. Thanks Link to comment Share on other sites More sharing options...
Bert Posted November 3, 2008 Share Posted November 3, 2008 You may have better luck using a inifile to do what you need. It looks like you are trying to put in the weekday into a text file for reference. iniread iniwrite The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
November Posted November 3, 2008 Share Posted November 3, 2008 Haha I have one final question to get this fully working. Is it possible to write data to a hidden text file?. I don't really want to remove the hidden attribute. ThanksHi there, Yes you can! #Include <File.au3> $file = "c:\test.txt" _FileCreate($file) FileSetAttrib($file, "+H") FileWrite($file, "Got it!") run("notepad c:\test.txt", "c:") Cheers Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now