Jump to content

Displaying text from .txt file in msgbox issues


 Share

Recommended Posts

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

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

:mellow:

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

  • Developers

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

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 by jbennett
Link to comment
Share on other sites

Thanks,

That works as a whole but as soon as I comment out the write bit it doesn't display anything in the msgbox

Not sure why?

thanks

EDIT

----

Haha I know why, I didn't have any data in the .txt file.

Thanks

To quote the sage philosopher Homer: Doh! :mellow:

:(

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

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

Hi 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

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