Page loading

Share your opinion
What do you think about gambaslinux.fr?
 
Interesting
It miss some informations
Excellent website
Results
WIDGETS GAMBAS
GAMBAS 3 SOFTWARES
TUTORIALS
Library
work with files - Use Text files
USE TEXT FILES


hye,
today, we use a text file with summary command such as Open, close, copy, paste, etc...



OPEN A TEXT FILE
Open a file in gambas is simple
Define 2 variables :
Myfile AS File
Myline AS String


now, you open the file and make a end of file test with loop :

WHILE NOT eof
WEND

Here the complete code:
DIM monfichier AS File
DIM maligne AS String
monfichier = OPEN "/chemindufichier/" FOR INPUT
WHILE NOT eof(monfichier)
LINE INPUT #monfichier, maligne
print maligne
WEND

In this example, we send all string to the terminal console using PRINT instruction.
we could send string in a textarea by the command :

textarea1.insert(maligne)

CLOSE A FILE

Don't forget to close the file by the command :

CLOSE #monfichier

Tips : It not necessary to close your file in gb but if you 're a great coder, you do it :)



SEARCH STRING

To search string, use the lnStr command who search in a string and return the position.

example :
numero =  Instr(maligne , "toto")

It means in the string maligne, search the string "toto" and put  the position in toto variable
 
if the maligne string is : "bonjour toto tu vas bien?", numerowill be : 9



COUNT LINE IN A FILE

Insert in the WHILE NOT WEND boucle a "numeroligne" integer variable and increment it when you feed back the bouclewith INC command  :

DIM monfichier AS File
DIM maligne AS String
DIM numeroligne AS Integer
numeroligne = 0
monfichier = OPEN "/chemindufichier/" FOR INPUT
WHILE NOT eof(monfichier)
LINE INPUT #monfichier, maligne
print maligne
inc numeroligne
WEND

Have a good day !
tongue




Creation date : 03/10/2009 @ 16:25
Last update : 27/01/2012 @ 21:36
Category : work with files
Page read 5919 times


Print the article Print the article


react.gifReactions to this article


Reaction #2 

by jackGab 10/03/2011 @ 18:52

Merci pour ce tuto Très bien mais
Il manque aussi l'exemple en écriture que j'ai eu du mal a trouver.

'On ouvre le fichier en écriture
fichier = OPEN" /home/../fichier.txt "FOR APPEND
            'on écrit dans le fichier           
            PRINT #fichier, TextBoxNom.Text
            PRINT #fichier, TextBoxPass.Text
            CLOSE #fichier

QUICK MENU
SEARCH




LANGUAGE
COMPONENTS
Other
LANGUAGE
Where, who?
VISITS

   visitors

   visitors online

ARCHIVES GAMBAS 1/2
^ Top ^