[Gambas-user] Writing to a file on disk
NW
hiems at ...2501...
Wed Nov 10 19:03:16 CET 2010
On Wed, 10 Nov 2010 17:14:24 +0100
Rolf-Werner Eilert <eilert-sprachen at ...221...> wrote:
> >
>
> Maybe it's better you give us the lines you are using in your program to
> read and write the line. Then we should be able to see where the bug
> sits :-)
>
> Did you try the File functions to do this? These should work without any
> headache: File.Read and File.Write. Look them up in the help.
>
> If you prefer to open a stream for file writing, there are more things
> to be considered, best is you give us an idea of what you have written
> there...
>
> Regards
>
> Rolf
>
Here is some more information.
I have a form which includes two buttons. The first one is for reading in the file, (which has only one line of text). Here is my coding.
PUBLIC SUB Button1_Click()
DIM lineIn AS String
DIM fileIn AS File
DIM fname AS String
fname = "/home/neilwin/basic/trial.txt"
OPEN fname FOR READ AS #fileIn
LINE INPUT #fileIn, lineIn
result.Text = ""
result.text = result.text & lineIn
FLUSH #fileIn
CLOSE #fileIn
END
There is also a text box which I have renamed result. I make a few changes to the line of text and then I click on another button to write the changed file back to the hard disk. Here is the code
PUBLIC SUB Button3_Click()
DIM fileIn AS File
DIM fname AS String
fname = "/home/neilwin/basic/trial.txt"
OPEN fname FOR CREATE AS #fileIn
WRITE #fileIn, result.Text
CLOSE #fileIn
END
Perhaps I should add that I am new to Gambas but not new to computers.
When I check the new version of the file in Konqueror the changes are there but there is one extra character at the very start of the line.
Is there a better way to do what I want? Thanks for any help,
Neil
More information about the User
mailing list