Jump to content
Sign in to follow this  
jbennett

Displaying text from .txt file in msgbox issues

Recommended Posts

jbennett

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)

Share this post


Link to post
Share on other sites
jbennett

Thanks but i've tried that and it doesn't work

$test=Fileread(@scriptdir & "\test.txt")

msgbox (0,"TEST","",$test)

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
jbennett

I'm confused. I thought the code I just posted is correct

Share this post


Link to post
Share on other sites
Jos

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)

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
jbennett

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

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
jbennett

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

Share this post


Link to post
Share on other sites
November

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]

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  

×