[Gambas-user] Writing to a file on disk

Matti math.eber at ...221...
Wed Nov 10 19:48:20 CET 2010


If you want to store just a few informations from your project, there is also
the very simple way via the gb.settings component.

You have to choose this component in the project properties first.

Then (this is Gambas3, look in the docs if you use Gambas2):
Write:
Settings["MyText/1"] = result.Text
Read:
result.Text = Settings["MyText/1"]

The automagically generated file MyProject.conf is stored in ~/.config/gambas(3).

So, if you don't have to save "real" files, you don't have to care about
opening, reading, writing and closing files at all.

Regards
Matti


Am 10.11.2010 19:03, schrieb NW:
> 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
> 




More information about the User mailing list