[VB]Prob ds Do While not EOF
Résolu
RDPnyX
Messages postés
157
Statut
Membre
-
Utilisateur anonyme -
Utilisateur anonyme -
bonjour bonjour, je commence a me mettre a la programation, donc ça doit etre mon premier post dans cette section, il faut savoir que je comprends a peut pres le langage, mais pr produire moi meme j'ai encore du mal, donc je modifie du code libre existant.
Voila mon probleme:
j'ai un fichier txt contenant ceci:
'\Documents and Settings\|\Program Files\Palm\|\program files\BOV5\BusinessObjects 5.0\LocData\|\program files\BOV5\BusinessObjects\LocData\|\program files\NetMeeting\Numérotation abrégée\|\program files\Services en ligne\Compuserve\Fcabinet\|\program files\Services en ligne\Compuserve\Support\Addrbook.dat\|\program files\pcanywhere\data\|\sys\cx\tomnt.ini\|\sys\cx\tomnt.log\|\sys\cx\toolspsa\exec\exec.ini\|\sys\cx\toolspsa\exec\params.txt\|\sys\cx\toolspsa\scanner\params.txt\|\sys\cx\toolspsa\scanner\scanner.ini\|\sys\orawin95\network\admin\|\sys\orawinnt\network\admin\|\sys\pcom\private\|\sys\windows\favoris\|\sys\windows\tt340iw.ini\|\sys\windows\ttw32ftp.ini\|\user\'
sur une seule ligne, mon but est de rcupérer chaque chemin qui est séparé par un pipe (|) dans un tableau. sans en etre au tableau, je rencontre une erreur dans mon code et je vois pas pourquoi!
le voici:
Private Sub Command1_Click()
Dim NumFich As Integer
Dim Tampon As String
Dim iPosD1 As Integer
Dim iPosD2 As Integer
Dim PremiereChaineRch As String
Dim SecondeChaineRch As String
Dim ChaineFin As String
NumFich = FreeFile
Open "C:\NetBackupAddVB\export netbackup\TESTLanIncludeSelectionList.txt" For Binary Access Read Lock Read As #NumFich
'Input #NumFich, Tampon
Tampon = Input(LOF(NumFich), #NumFich)
Close #NumFich
PremiereChaineRch = "'"
SecondeChaineRch = ""
Debug.Print Tampon
Do While Not EOF(NumFich)
PremiereChaineRch = PremiereChaineRch + "\"
SecondeChaineRch = SecondeChaineRch + "|"
iPosD1 = InStr(1, Tampon, PremiereChaineRch)
If (iPosD1 > 0) Then 'Si "\" trouvé
iPosD2 = InStr(iPosD1 + Len(PremiereChaineRch), Tampon, SecondeChaineRch)
If (iPosD2 > 0) Then
ChaineFin = Mid$(Tampon, iPosD1 + Len(PremiereChaineRch), iPosD2 - (iPosD1 + Len(PremiereChaineRch)))
ChaineFin = Replace(ChaineFin, vbCrLf, "")
Debug.Print ChaineFin
'mettre ChaineFin dans la case du tableau qui va bien
Else
MsgBox "Impossible de trouver la chaine de fin d'extraction..."
End If
Else
MsgBox "Impossible de trouver la chaine de début d'extraction..."
End If
Loop
End Sub
l'erreur se situe au niveau du while not EOF, VB me dit que le nom de fichier ou le numero est incorrect. Hors j'ai essayer avec #NumFich, Tampon, NumFich, bref les trucs possibles, mais niet, rien, marche pas. Help!
Merci d'avance
Voila mon probleme:
j'ai un fichier txt contenant ceci:
'\Documents and Settings\|\Program Files\Palm\|\program files\BOV5\BusinessObjects 5.0\LocData\|\program files\BOV5\BusinessObjects\LocData\|\program files\NetMeeting\Numérotation abrégée\|\program files\Services en ligne\Compuserve\Fcabinet\|\program files\Services en ligne\Compuserve\Support\Addrbook.dat\|\program files\pcanywhere\data\|\sys\cx\tomnt.ini\|\sys\cx\tomnt.log\|\sys\cx\toolspsa\exec\exec.ini\|\sys\cx\toolspsa\exec\params.txt\|\sys\cx\toolspsa\scanner\params.txt\|\sys\cx\toolspsa\scanner\scanner.ini\|\sys\orawin95\network\admin\|\sys\orawinnt\network\admin\|\sys\pcom\private\|\sys\windows\favoris\|\sys\windows\tt340iw.ini\|\sys\windows\ttw32ftp.ini\|\user\'
sur une seule ligne, mon but est de rcupérer chaque chemin qui est séparé par un pipe (|) dans un tableau. sans en etre au tableau, je rencontre une erreur dans mon code et je vois pas pourquoi!
le voici:
Private Sub Command1_Click()
Dim NumFich As Integer
Dim Tampon As String
Dim iPosD1 As Integer
Dim iPosD2 As Integer
Dim PremiereChaineRch As String
Dim SecondeChaineRch As String
Dim ChaineFin As String
NumFich = FreeFile
Open "C:\NetBackupAddVB\export netbackup\TESTLanIncludeSelectionList.txt" For Binary Access Read Lock Read As #NumFich
'Input #NumFich, Tampon
Tampon = Input(LOF(NumFich), #NumFich)
Close #NumFich
PremiereChaineRch = "'"
SecondeChaineRch = ""
Debug.Print Tampon
Do While Not EOF(NumFich)
PremiereChaineRch = PremiereChaineRch + "\"
SecondeChaineRch = SecondeChaineRch + "|"
iPosD1 = InStr(1, Tampon, PremiereChaineRch)
If (iPosD1 > 0) Then 'Si "\" trouvé
iPosD2 = InStr(iPosD1 + Len(PremiereChaineRch), Tampon, SecondeChaineRch)
If (iPosD2 > 0) Then
ChaineFin = Mid$(Tampon, iPosD1 + Len(PremiereChaineRch), iPosD2 - (iPosD1 + Len(PremiereChaineRch)))
ChaineFin = Replace(ChaineFin, vbCrLf, "")
Debug.Print ChaineFin
'mettre ChaineFin dans la case du tableau qui va bien
Else
MsgBox "Impossible de trouver la chaine de fin d'extraction..."
End If
Else
MsgBox "Impossible de trouver la chaine de début d'extraction..."
End If
Loop
End Sub
l'erreur se situe au niveau du while not EOF, VB me dit que le nom de fichier ou le numero est incorrect. Hors j'ai essayer avec #NumFich, Tampon, NumFich, bref les trucs possibles, mais niet, rien, marche pas. Help!
Merci d'avance
A voir également:
- [VB]Prob ds Do While not EOF
- Input not supported - Forum Ecran
- Do not turn off target traduction - Forum Samsung
- Samsung galaxy tab S Bloquer Downloading do not turn off target - Forum Téléphones & tablettes Android
- Not able to play iron tv ✓ - Forum TV & Vidéo
- Signal cable not connected - Forum Ecran
2 réponses
Bonjour,
**********************************************
Tampon = Input(LOF(NumFich), #NumFich)
->>>>>Close #NumFich
PremiereChaineRch = "'"
SecondeChaineRch = ""
Debug.Print Tampon
Do While Not EOF(NumFich) ' Le fichier est fermé !
**********************************************
Ne travaille plus avec le fichier, il est fermé.
Tu possède une chaine [Tampon], alors travaille avec ...
EX.:
Dim Longueur,I As Long
Dim Carac As String
Longueur = Len(Tampon)
For I = 1 To Longueur
..Carac = Mid(Tampon,I,1)
..If ( Carac = "|" ) Then
...."Décortiquer la chaine ...
..End If
Next I
Lupin
**********************************************
Tampon = Input(LOF(NumFich), #NumFich)
->>>>>Close #NumFich
PremiereChaineRch = "'"
SecondeChaineRch = ""
Debug.Print Tampon
Do While Not EOF(NumFich) ' Le fichier est fermé !
**********************************************
Ne travaille plus avec le fichier, il est fermé.
Tu possède une chaine [Tampon], alors travaille avec ...
EX.:
Dim Longueur,I As Long
Dim Carac As String
Longueur = Len(Tampon)
For I = 1 To Longueur
..Carac = Mid(Tampon,I,1)
..If ( Carac = "|" ) Then
...."Décortiquer la chaine ...
..End If
Next I
Lupin
re:
ce fut un plaisir, et ne t'inquiète pas je cherche aussi très
souvent, parfois un oeil externe nous permets de faire des
pas. Trop concentré sur un problème posé, on n'y voit plus
rien!
je serais tenter par quelque chose du genre :
Dim Chaine(50) As String
Dim NbrChaine As Integer
Dim Position as Integer
Dim Flag As Boolean
NbrChaine=0
Flag = True
Longueur = Len(Tampon)
While (Flag)
..For I = 1 To Longueur
....Carac = Mid(Tampon,I,1)
....If ( Carac = "|" ) Then
......Position = I
......NbrChaine = (NbrChaine + 1)
......Chaine(NbrChaine) = Mid(Tampon,1,Position)
......Tampon = Mid(Tampon, (Position+1))
......I = (Longueur +1) ' Sortie de la boucle
....End If
..Next I
..Longueur = Len (Tampon)
..If (Longueur < 1) Then
....Flag = False
..End IF
Wend
For I = 1 To NbrChaine
..MsgBox Chaine(I)
Next I
Un petit bout de code le matin, rien de tel pour se réveiller :)
Lupin
ce fut un plaisir, et ne t'inquiète pas je cherche aussi très
souvent, parfois un oeil externe nous permets de faire des
pas. Trop concentré sur un problème posé, on n'y voit plus
rien!
je serais tenter par quelque chose du genre :
Dim Chaine(50) As String
Dim NbrChaine As Integer
Dim Position as Integer
Dim Flag As Boolean
NbrChaine=0
Flag = True
Longueur = Len(Tampon)
While (Flag)
..For I = 1 To Longueur
....Carac = Mid(Tampon,I,1)
....If ( Carac = "|" ) Then
......Position = I
......NbrChaine = (NbrChaine + 1)
......Chaine(NbrChaine) = Mid(Tampon,1,Position)
......Tampon = Mid(Tampon, (Position+1))
......I = (Longueur +1) ' Sortie de la boucle
....End If
..Next I
..Longueur = Len (Tampon)
..If (Longueur < 1) Then
....Flag = False
..End IF
Wend
For I = 1 To NbrChaine
..MsgBox Chaine(I)
Next I
Un petit bout de code le matin, rien de tel pour se réveiller :)
Lupin
sinon, ton code va m'aider, pr le moment, ajouté à celui que j'avais, ça me ressors que la premiere chaine (Documents and Settings\) mais ne t'embetes pas à chercher, je vais le faire moi meme.
merci encore pr ta réponse.