Extraire des infos d'1 fichier text en vb

Résolu
kg_online Messages postés 39 Date d'inscription dimanche 28 novembre 2004 Statut Membre Dernière intervention 4 juin 2007 - 4 févr. 2005 à 12:16
cs_ITALIA Messages postés 2169 Date d'inscription vendredi 20 avril 2001 Statut Membre Dernière intervention 30 juin 2009 - 7 févr. 2005 à 08:34
<HR>
Bonjour tout le monde,

j'ai crée un fichier config (fichier text ) sur mon buro et j'aimerai utiler les données qui s'y trouvent dans un programme principale.Cependant j'ai essayé de stocker chaque ligne lue de ce fichier text dans un tableau() pour pouvoir ensuite en déhord de cette fonction utiliser n'importe quelle valeur du tableau par exemple:
tableau(1) m'affiche la ligne lu......
tableau(54) m'affiche la ligne lu...etc...
le problème problème est que ça affiche tout en même temps.
Merci d'avance!
Voici mon programme!


Function FileRead2(ByVal strFile As String)<?xml:namespace prefix o ns "urn:schemas-microsoft-com:office:office" />





Private Sub Command1_Click()




Dim i As Integer


'Déclaration de tableau


Dim Max(1 To 23) As Double


'Créer une instance du FSO


Set fso = New Scripting.FileSystemObject





' Ouvrir le fichier en écriture


strFile = "c:\documents and settings\????????\bureau\test.txt"


Set stm = fso.GetFile(strFile).OpenAsTextStream(ForReading)


While Not stm.AtEndOfStream


strTemp = stm.ReadLine


For i = 1 To 23


Max(i) = strTemp


Next i


‘ Affichage des lignes lues


MsgBox Max(i - 1)


Wend


' Libérer les objets


stm.Close


Set stm = Nothing


Set fso = Nothing





End Sub

7 réponses

cs_ITALIA Messages postés 2169 Date d'inscription vendredi 20 avril 2001 Statut Membre Dernière intervention 30 juin 2009 9
4 févr. 2005 à 13:12
Open "c:\documents and settings\????????\bureau\test.txt" For Input As #1
Do Until EOF(1)
i=i+1
Line Input #1, Ligne
Max(i) = Ligne
Loop
Close #1
3
cs_the_best Messages postés 212 Date d'inscription jeudi 13 novembre 2003 Statut Membre Dernière intervention 6 avril 2006
4 févr. 2005 à 13:11
Peut être que comme ça ça marchera :

Public sub ouvremoicefichier(nom_fichier as string)
Dim resultats(10)
n_resultats = 0

Open nom_fichier for input as 1
While Not eof(1)
Line input #1, agnu
resultats(n_resultats) = agnu
Wend

End sub

The Best

Glu !!! [VIVE LINUX. Saviez vous qu'il existe Gambas pour remplacer Vb sous linux ? ]
0
kg_online Messages postés 39 Date d'inscription dimanche 28 novembre 2004 Statut Membre Dernière intervention 4 juin 2007
4 févr. 2005 à 13:57
Désolé the best mais ton prog ne marche pas peut être que t'as omis quelque chose.
Merci
0
kg_online Messages postés 39 Date d'inscription dimanche 28 novembre 2004 Statut Membre Dernière intervention 4 juin 2007
4 févr. 2005 à 14:08
Merci Italia ça marche impect!!!!!!!!!!!!!
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_ITALIA Messages postés 2169 Date d'inscription vendredi 20 avril 2001 Statut Membre Dernière intervention 30 juin 2009 9
4 févr. 2005 à 16:14
De Rien @+

It@li@
0
romtrico064649 Messages postés 14 Date d'inscription lundi 6 novembre 2000 Statut Membre Dernière intervention 1 juillet 2009
4 févr. 2005 à 16:38
Bonjour,
Ce code pour lire un fichier .ini pourais t'être utile :

'####################################APIs Déclaration####################################################################
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'Paramétres :
'#lpApplicationName
'The header of the INI file section the value Is In.
'#lpKeyName
'The Name of the value To Read.
'#lpDefault
'The value To return If a valid value cannot be Read. Make it something that would definitely Not be Read, such As "(error)".
'#lpReturnedString
'A fixed-length String that will receive either the String Read from the file Or lpDefault.
'nSize
'The length In characters of lpReturnedString.
'#lpFileName
'The filename of the INI file To Read from.
'#########################################################################################################################
'##########################################################################################################################
'##Retourne sous forme de string la valeur de l'élement strName de la section strSection du fichier selectedPath & config.ini
'##Retourne NONE en cas d'échec
'######################################
Function getListParamInitFileFor(strSection As String, strName As String) As String
Dim strPath As String, strFileName As String
Dim strRes As String*100
Dim lRes As Long

strPath = "c:" 'SelectedPath
strFileName = "Config.ini"
lRes = GetPrivateProfileString(strsection, strName, "NONE", strRes, 100, strPath & "" & strFileName)
MsgBox "len : " & lRes & " res : " & strRes
End Function

Pour lire un fichier .ini du type :

;Debut du fichier : c:\Config.ini
;=====================================================
PAGE D'INFORMATION PERSONELLE
;=====================================================


[Ma section]
;-----------------------------------------------------
Prenom=Romain
Age=27

[Ma section2]
......

Pour lire la clée Prenom de ce fichier init :
msgbox getListParamInitFileFor("Ma section", "Prenom")

retourne "Romain"

Salut

RomTrico
0
cs_ITALIA Messages postés 2169 Date d'inscription vendredi 20 avril 2001 Statut Membre Dernière intervention 30 juin 2009 9
7 févr. 2005 à 08:34
Oui mais dans son cas c'est du TXT

It@li@
0
Rejoignez-nous