OVH Cloud OVH Cloud

recuperation de donne d'un fichier texte

13 réponses
Avatar
squat541
salut
voila g un fichier texte avec 85.22 j'arrive a recuperer 85 dans le tableau
1 et 22 dans le tableau 2 grace au prog suivant
Dim t1(1 to 3)
Dim t2(1 to 3)
Dim st as String
Dim n as String
open "adresse.txt" for input As #1
for i=1 to 3
input #1,st
n= Instr(st, ".")
t1(i)=Cint(Left(st,n-1))
t2(i)=Cint(Mid(st,n+1))
next i
close #1
jusqu'ici tout va bien mais maintenant j'aimerais savoir commen faire pour 3
champ
c'est a dire 85.22.5 par exemple
est que quelqu'un connait la reponse

3 réponses

1 2
Avatar
Pascal B.
Qu'est-ce-qu'elle t'a fait la fonction Split (plus simple) pour que tu ne veuilles absulement pas l'employer ????


"squat541" wrote in message news:
| merci a tous,je vien de recevoir la soluce par mail
| For I=1 to 3
| Input#1,St
| N=InStr(St,".")
| T1(I)=Cint(Left(ST,N-1))
| St=Mid(St,N+1)
| N=Instr(St,".")
| T2(I)=Cint(Left(ST,N-1))
| T3(I)=Cint(Mid(ST,N+1))
| Next
| Close
|
|
| "Driss HANIB" a écrit :
|
| > Oui c'est vrai,
| > mais comme squat541 lit à partir d'un fichier texte cela ne change pas le
| > problème.. D'une manière ou une autre il devra convertir..
| >
| > Driss
| >
| > "Patrice Henrio" a écrit dans le message de
| > news:
| > > Le problème du split c'est qu'il va donner des chaines et qu'il va falloir
| > > ensuite entrer les valeurs avec CInt dasn les trois tableaux
| > > Dim T() as string
| > > Avec un fichier texte comportant 4 lignes
| > > For I=1 to 4
| > > Input#1,ST
| > > T=Split(ST,".")
| > > T1(I)=CInt(T(0))
| > > T2(I)=Cint(T(1))
| > > T3(I)=Cint(T(2))
| > > Next
| > >
| > >
| > > Autre solution
| > > TabEntiers(1 to 3,1 to 4) as byte
| > > For I=1 to 4
| > > Input#1,ST
| > > T=Split(ST,".")
| > > For J=1 to 3
| > > T(J,I)=CInt(T(J-1))
| > > Next J
| > > Next I
| > >
| > >
| > > "squat541" a écrit dans le message de
| > > news:
| > > > et commen tu fait par exemple avec mes 3 tableaux
| > > >
| > > > "Driss HANIB" a écrit :
| > > >
| > > >> Bonjour,
| > > >>
| > > >> si tu as VB6, utilise la commande Split qui va créer un tableau en
| > > >> coupant à
| > > >> chaque point.
| > > >>
| > > >> Driss
| > > >>
| > > >> "squat541" a écrit dans le message
| > > >> de
| > > >> news:
| > > >> > salut
| > > >> > voila g un fichier texte avec 85.22 j'arrive a recuperer 85 dans le
| > > >> tableau
| > > >> > 1 et 22 dans le tableau 2 grace au prog suivant
| > > >> > Dim t1(1 to 3)
| > > >> > Dim t2(1 to 3)
| > > >> > Dim st as String
| > > >> > Dim n as String
| > > >> > open "adresse.txt" for input As #1
| > > >> > for i=1 to 3
| > > >> > input #1,st
| > > >> > n= Instr(st, ".")
| > > >> > t1(i)=Cint(Left(st,n-1))
| > > >> > t2(i)=Cint(Mid(st,n+1))
| > > >> > next i
| > > >> > close #1
| > > >> > jusqu'ici tout va bien mais maintenant j'aimerais savoir commen faire
| > > >> > pour
| > > >> 3
| > > >> > champ
| > > >> > c'est a dire 85.22.5 par exemple
| > > >> > est que quelqu'un connait la reponse
| > > >> >
| > > >>
| > > >>
| > > >>
| > >
| > >
| >
| >
| >
Avatar
squat541
Ouais c vrai quelle est tres facile

"Pascal B." a écrit :


Dim T1() as Byte, T2() as Byte, T3() as Byte
Dim i as Integer
Dim St as String
Dim Tmp() as String

'...
i = 0
Do until EOF(1)
i=i + 1
Redim Preserve T1(i), T2(i), T3(i)
Input#1, St
Tmp() = Split(St,".")
T1(i) = CInt(Tmp(0))
T2(i) = CInt(Tmp(1))
T3(i) = CInt(Tmp(2))
Loop

Enfin, si tu ne veux toujours pas de Split, tu peux encore adapter le code avec Instr, Mid, Left, N+1, N-1, etc ...

Cordialement
Pascal

"squat541" wrote in message news:
| mais sinon commen faire pour que le tableau se remplisseselon le nbre de ligne
| par ex que je n'ai une 14 ligne ,une autre fois 18 ligne et qui change la
| valeur max du tableau
|
|
| "squat541" a écrit :
|
| > merci a tous,je vien de recevoir la soluce par mail
| > For I=1 to 3
| > Input#1,St
| > N=InStr(St,".")
| > T1(I)=Cint(Left(ST,N-1))
| > St=Mid(St,N+1)
| > N=Instr(St,".")
| > T2(I)=Cint(Left(ST,N-1))
| > T3(I)=Cint(Mid(ST,N+1))
| > Next
| > Close
| >
| >
| > "Driss HANIB" a écrit :
| >
| > > Oui c'est vrai,
| > > mais comme squat541 lit à partir d'un fichier texte cela ne change pas le
| > > problème.. D'une manière ou une autre il devra convertir..
| > >
| > > Driss
| > >
| > > "Patrice Henrio" a écrit dans le message de
| > > news:
| > > > Le problème du split c'est qu'il va donner des chaines et qu'il va falloir
| > > > ensuite entrer les valeurs avec CInt dasn les trois tableaux
| > > > Dim T() as string
| > > > Avec un fichier texte comportant 4 lignes
| > > > For I=1 to 4
| > > > Input#1,ST
| > > > T=Split(ST,".")
| > > > T1(I)=CInt(T(0))
| > > > T2(I)=Cint(T(1))
| > > > T3(I)=Cint(T(2))
| > > > Next
| > > >
| > > >
| > > > Autre solution
| > > > TabEntiers(1 to 3,1 to 4) as byte
| > > > For I=1 to 4
| > > > Input#1,ST
| > > > T=Split(ST,".")
| > > > For J=1 to 3
| > > > T(J,I)=CInt(T(J-1))
| > > > Next J
| > > > Next I
| > > >
| > > >
| > > > "squat541" a écrit dans le message de
| > > > news:
| > > > > et commen tu fait par exemple avec mes 3 tableaux
| > > > >
| > > > > "Driss HANIB" a écrit :
| > > > >
| > > > >> Bonjour,
| > > > >>
| > > > >> si tu as VB6, utilise la commande Split qui va créer un tableau en
| > > > >> coupant à
| > > > >> chaque point.
| > > > >>
| > > > >> Driss
| > > > >>
| > > > >> "squat541" a écrit dans le message
| > > > >> de
| > > > >> news:
| > > > >> > salut
| > > > >> > voila g un fichier texte avec 85.22 j'arrive a recuperer 85 dans le
| > > > >> tableau
| > > > >> > 1 et 22 dans le tableau 2 grace au prog suivant
| > > > >> > Dim t1(1 to 3)
| > > > >> > Dim t2(1 to 3)
| > > > >> > Dim st as String
| > > > >> > Dim n as String
| > > > >> > open "adresse.txt" for input As #1
| > > > >> > for i=1 to 3
| > > > >> > input #1,st
| > > > >> > n= Instr(st, ".")
| > > > >> > t1(i)=Cint(Left(st,n-1))
| > > > >> > t2(i)=Cint(Mid(st,n+1))
| > > > >> > next i
| > > > >> > close #1
| > > > >> > jusqu'ici tout va bien mais maintenant j'aimerais savoir commen faire
| > > > >> > pour
| > > > >> 3
| > > > >> > champ
| > > > >> > c'est a dire 85.22.5 par exemple
| > > > >> > est que quelqu'un connait la reponse
| > > > >> >
| > > > >>
| > > > >>
| > > > >>
| > > >
| > > >
| > >
| > >
| > >





Avatar
Pascal B.
Dim T1() as Byte, T2() as Byte, T3() as Byte
Dim i as Integer
Dim St as String
Dim Tmp() as String

'...
i = 0
Do until EOF(1)
i=i + 1
Redim Preserve T1(i), T2(i), T3(i)
Input#1, St
Tmp() = Split(St,".")
T1(i) = CInt(Tmp(0))
T2(i) = CInt(Tmp(1))
T3(i) = CInt(Tmp(2))
Loop

Enfin, si tu ne veux toujours pas de Split, tu peux encore adapter le code avec Instr, Mid, Left, N+1, N-1, etc ...

Cordialement
Pascal

"squat541" wrote in message news:
| mais sinon commen faire pour que le tableau se remplisseselon le nbre de ligne
| par ex que je n'ai une 14 ligne ,une autre fois 18 ligne et qui change la
| valeur max du tableau
|
|
| "squat541" a écrit :
|
| > merci a tous,je vien de recevoir la soluce par mail
| > For I=1 to 3
| > Input#1,St
| > N=InStr(St,".")
| > T1(I)=Cint(Left(ST,N-1))
| > St=Mid(St,N+1)
| > N=Instr(St,".")
| > T2(I)=Cint(Left(ST,N-1))
| > T3(I)=Cint(Mid(ST,N+1))
| > Next
| > Close
| >
| >
| > "Driss HANIB" a écrit :
| >
| > > Oui c'est vrai,
| > > mais comme squat541 lit à partir d'un fichier texte cela ne change pas le
| > > problème.. D'une manière ou une autre il devra convertir..
| > >
| > > Driss
| > >
| > > "Patrice Henrio" a écrit dans le message de
| > > news:
| > > > Le problème du split c'est qu'il va donner des chaines et qu'il va falloir
| > > > ensuite entrer les valeurs avec CInt dasn les trois tableaux
| > > > Dim T() as string
| > > > Avec un fichier texte comportant 4 lignes
| > > > For I=1 to 4
| > > > Input#1,ST
| > > > T=Split(ST,".")
| > > > T1(I)=CInt(T(0))
| > > > T2(I)=Cint(T(1))
| > > > T3(I)=Cint(T(2))
| > > > Next
| > > >
| > > >
| > > > Autre solution
| > > > TabEntiers(1 to 3,1 to 4) as byte
| > > > For I=1 to 4
| > > > Input#1,ST
| > > > T=Split(ST,".")
| > > > For J=1 to 3
| > > > T(J,I)=CInt(T(J-1))
| > > > Next J
| > > > Next I
| > > >
| > > >
| > > > "squat541" a écrit dans le message de
| > > > news:
| > > > > et commen tu fait par exemple avec mes 3 tableaux
| > > > >
| > > > > "Driss HANIB" a écrit :
| > > > >
| > > > >> Bonjour,
| > > > >>
| > > > >> si tu as VB6, utilise la commande Split qui va créer un tableau en
| > > > >> coupant à
| > > > >> chaque point.
| > > > >>
| > > > >> Driss
| > > > >>
| > > > >> "squat541" a écrit dans le message
| > > > >> de
| > > > >> news:
| > > > >> > salut
| > > > >> > voila g un fichier texte avec 85.22 j'arrive a recuperer 85 dans le
| > > > >> tableau
| > > > >> > 1 et 22 dans le tableau 2 grace au prog suivant
| > > > >> > Dim t1(1 to 3)
| > > > >> > Dim t2(1 to 3)
| > > > >> > Dim st as String
| > > > >> > Dim n as String
| > > > >> > open "adresse.txt" for input As #1
| > > > >> > for i=1 to 3
| > > > >> > input #1,st
| > > > >> > n= Instr(st, ".")
| > > > >> > t1(i)=Cint(Left(st,n-1))
| > > > >> > t2(i)=Cint(Mid(st,n+1))
| > > > >> > next i
| > > > >> > close #1
| > > > >> > jusqu'ici tout va bien mais maintenant j'aimerais savoir commen faire
| > > > >> > pour
| > > > >> 3
| > > > >> > champ
| > > > >> > c'est a dire 85.22.5 par exemple
| > > > >> > est que quelqu'un connait la reponse
| > > > >> >
| > > > >>
| > > > >>
| > > > >>
| > > >
| > > >
| > >
| > >
| > >
1 2