[Gambas-user] Writing to a file on disk
Fabien Bodard
gambas.fr at ...626...
Wed Nov 10 19:21:47 CET 2010
have you tryed to replace result by a global string variable ?
textbox use utf8 charset
and yes in your case ... use file.save
to resume your code
Private $sResult as string
PUBLIC SUB Button1_Click()
$sResult = File.Load("/home/neilwin/basic/trial.txt")
END
PUBLIC SUB Button3_Click()
File.Save("/home/neilwin/basic/trial.txt", $sResult)
END
But i think you want to modify somethong on a line so :
dim s as string
Dim sFile as string
Dim hFile as File
Dim sTempName as String
Dim sMyFile as String = "/home/neilwin/basic/trial.txt"
sTempName = Temp()
hFile = Open sTempName FOR CREATE
sFile = File.Load( sMyFile)
For each s in split(sFile, "\n")
if trim(s) Begin "Var=" then
s = "coucou"
endif
print #hFile, s
next
close #hfile
kill sMyFile
copy sTempFile TO sMyFile
2010/11/10 NW <hiems at ...2501...>:
> 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
>
> ------------------------------------------------------------------------------
> The Next 800 Companies to Lead America's Growth: New Video Whitepaper
> David G. Thomson, author of the best-selling book "Blueprint to a
> Billion" shares his insights and actions to help propel your
> business during the next growth cycle. Listen Now!
> http://p.sf.net/sfu/SAP-dev2dev
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
--
Fabien Bodard
More information about the User
mailing list