Ecrire dans un fichier texte
Le
DP

Bonsoir,
Une question probablement évidente mais je débute avec VB6.
Je sais comment lire un fichier texte (Open "mon fichier" For Input #1)
Mais comment écrire dedans une liste de variables?
Merci de votre aide
DP
Une question probablement évidente mais je débute avec VB6.
Je sais comment lire un fichier texte (Open "mon fichier" For Input #1)
Mais comment écrire dedans une liste de variables?
Merci de votre aide
DP
Open "mon fichier" For Input #1
dans un projet
Tu te positionnes sur Input et tu appuies sur F1
Et là tu te laisses guider.
Si tu n'as pas MSDN, c'est indispensable. Je crois qu'il y a des sites où on
peut le télécharger.
"DP"
Il faut ouvrir le fichier en écriture, soit en mode
"Output" soit en mode "Append". Voir l'aide du statement
Open ici:
http://msdn.microsoft.com/library/en-us/vbenlr98/html/vastmOpen.asp
sinon, pour écrire, c'est aussi simple que pour lire:
les instructions sont INPUT et LINE INPUT.
Voir l'aide ici:
http://msdn.microsoft.com/library/en-us/vbenlr98/html/vastmInput.asp
et la:
http://msdn.microsoft.com/library/en-us/vbenlr98/html/vastmLineInput.asp
Et un mini exemple, pour écrire 2 variables,
un entier et une string, puis les relire:
' Code a placer dans un Command1_Click()
'
' Start
'
Private Sub Command1_Click()
Dim v_integer As Integer
Dim s_string As String
Dim f As Integer
' affectations des variables
v_integer = "12345"
s_string = "HELLO, WORLD!"
' ecriture des variables
f = FreeFile
Open "c:fictst.dat" For Output As #f
Print #f, v_integer
Print #f, s_string
Close #f
' reset des variables
v_integer = 0
s_string = ""
' lecture dans le fichier
f = FreeFile
Open "c:fictst.dat" For Input As #f
Input #f, v_integer
Line Input #f, s_string
Close #f
' controle
MsgBox "Lu dans le fichier:" & vbCrLf & _
"v_integer=" & v_integer & vbCrLf & _
"s_string=" & s_string
End Sub
' End code
'
'
--
Jean-marc
"There are only 10 kind of people
those who understand binary and those who don't."
"DP" news:
Dim k as Integer
'//Binaire :
k = FreeFile
Open strFichier For Binary as #k
Put #k,1,"ma chaine"
Close #k
'//Texte :
k = FreeFile
Open strFichier For Output as #k
Print #k,"ma chaine"
Close #k
--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/
DP wrote: