Après avoir oté le 1er "|" (Separator), je crée un tableau :
Do While Not Fic_Entree.AtEndOfStream
strtmp = Split(Replace(Fic_Entree.ReadAll,"|X","X"), vbCrLf) 'création tableau du fichier
strtmp_count = UBound(strtmp) 'nombre de lignes du fichier
'|X2918|08/09/2006|22h55|ALES860M|B8062-ALES860M|IMSA.EDIMENS|II9X|1|
'X2918|08/09/2006|22h55|ALES860M|B8062-ALES860M|IMSA.EDIMENS|II9X|1|
For i = LBound(strtmp) to Ubound(strtmp)
imax = 0
Dim MyArray
MyArray = Split(Trim(strtmp(i)), Separator, -1, 1) 'creation tableau de la ligne courante
'MsgBox MyArray(6) &vbCrLf& MyArray(0) &vbCrLf& MyArray(7)
'MsgBox strtmp(i) &vbCrLf& strtmp(i+1) &vbCrLf&_
' "ubound de MyArray " & Ubound(MyArray) &vbCrLf&_
' "array(1) : " & MyArray(1) &vbCrLf&_
' "array(2) : " & MyArray(2) &vbCrLf& "array(3) : " & MyArray(3) &vbCrLf&_
' "array(4) : " & MyArray(4) &vbCrLf& "array(5) : " & MyArray(5) &vbCrLf&_
' "array(6) : " & MyArray(6) &vbCrLf& "array(7) : " & MyArray(7)
'MsgBox "ron" &vbCrLf& MyArray(7)
imax = imax + 1
ReDim Preserve Tableau(7, imax)
Tableau(1, imax) = MyArray(6) 'MyArray(6) correspond à II9X
Tableau(2, imax) = MyArray(3) 'MyArray(3) correspond à ALES860M
Tableau(3, imax) = MyArray(1) 'MyArray(1) correspond à jj/mm/aaaa
Tableau(4, imax) = MyArray(2) 'MyArray(2) correspond à 22h55
Tableau(5, imax) = MyArray(4) 'MyArray(4) correspond à B8062-ALES860M
Tableau(6, imax) = MyArray(5) 'MyArray(5) correspond à IMSA.EDIMENS
Tableau(7, imax) = MyArray(7) 'MyArray(7) correspond à 1 (nbre de copy)
Mon problème, je suis nul en tableau.
Je transforme en asc la valeur de Tableau(1, imax) = MyArray(6) pour pouvoir
comparer Tableau(1, imax) et Tableau(1, imax+1)
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 18 sept. 2006 à 08:32
salut,
beh çà sera un début au moins.....
Private Sub Form_Load()
Dim aArrayAll() As String, sTmp As String
Dim FF As Integer, i As Integer, j As Integer
' lecture du fichier en tableau
FF = FreeFile
i = 0
Debug.Print "-- AVANT --"
Open "C:\test.txt" For Input As #FF
' on lit tout sans ligne vide
Do While Not EOF(FF)
Line Input #FF, sTmp
If LenB(sTmp) > 0 Then
' redim à la bonne taille
ReDim Preserve aArrayAll(i)
aArrayAll(i) = sTmp
'trace
Debug.Print sTmp
i = i + 1
End If
Loop
Close #FF
' tri sur (6)
For i = UBound(aArrayAll) To 1 Step -1
For j = 0 To i - 1
If Split(aArrayAll(j), "|")(6) > Split(aArrayAll(j + 1), "|")(6) Then
sTmp = aArrayAll(j)
aArrayAll(j) = aArrayAll(j + 1)
aArrayAll(j + 1) = sTmp
End If
Next j
Next i
' trace
Debug.Print vbCrLf & "-- APRèS --"
For i = 0 To UBound(aArrayAll)
Debug.Print aArrayAll(i)
Next i
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 17 sept. 2006 à 22:45
salut,
pas besoin de répondre à mon MP...
rubrique corrigée (elles sont côte à côte.. bizarre...)
NB : topic à peine survolé, si tu veux de l'aide en VB6 pourquoi pas en en VBS (tu dois le savoir) je ne m'y connais pas des masses...
++
<hr size="2" width="100%" />Prenez un instant pour répondre à ce sondage svp
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201827 17 sept. 2006 à 23:08
Bonsoir,
merci PCPT,
Je ne pratique pas le VB6, je n'utilise que le vbs pour faire du reporting
(fichiers Aix, Gcos, ou Db vers présentation html ou autres) pour une partie
de mon job et pour mon dilettantisme.
Mais un exemple en vb6, j'arriverai, peut-être, à comprendre sa logique, et,
à le translater en vbs.
J'arrive à trier, avec mes moyens archaiques (les miens), un tableau sur 1 ou 2 keys mais pas plus.
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 17 sept. 2006 à 23:30
re,
umm..."C:\test.txt" contient ce que tu as écris. (fini par "|", pas par un dernier retour chariot)
il t'attend patiemment... je ne comprends pas ce que tu veux réellement
en l'attente
ps : même sans l'utiliser mais si tu "comprends" VB (6 ou autre), tu peux le préciser en entête de topic. perso dès que je vois VBS ou DotNet je ne lis même pas alors que parfois une réponse en VB6 pourrait convenir...
++
<hr size="2" width="100%" />Prenez un instant pour répondre à ce sondage svp
Vous n’avez pas trouvé la réponse que vous recherchez ?
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201827 18 sept. 2006 à 06:46
Bonjour ,
J'ai un fichier .txt qui contient les lignes suivantes:
X2918|08/09/2006|22h55|ALES860M|B8062-ALES860M|IMSA.EDIMENS|II9X|1|
X2943|08/09/2006|23h02|ALES741M|B8224-ALES741M|IMSA.EDIMENS|II6X|1|
X2943|08/09/2006|23h02|ALES741M|B8224-ALES741M|IMSA.EDIMENS|PR05|1|
X2967|08/09/2006|23h19|PNEU741M|B8224-PNEU741M|IMSP.EDIMENS|II9X|1|
X2967|08/09/2006|23h19|PNEU741M|B8224-PNEU741M|IMSP.EDIMENS|PR05|1|
Mon délimitateur étant "|", j'aimerai trier (croissant ou décroissant) mon fichier sur MyArray(6), qui est le
nom des imprimantes, tout en gardant, évidemment, le contenu de la ligne.
MyArray(6) est toujours sur 4 caractères (2 lettres suivies de 2 caractères 'lettres ou chiffres').
Puis, le re-trier sur MyArray(4) quand MyArray(6) de la ligne courante = MyArray(6) de la ligne +1 (ou -1).
Résultat escompté dans un nouveau .txt :
X2943|08/09/2006|23h02|ALES741M|B8224-ALES741M|IMSA.EDIMENS|II6X|1|
X2918|08/09/2006|22h55|ALES860M|B8062-ALES860M|IMSA.EDIMENS|II9X|1|
X2967|08/09/2006|23h19|PNEU741M|B8224-PNEU741M|IMSP.EDIMENS|II9X|1|
X2943|08/09/2006|23h02|ALES741M|B8224-ALES741M|IMSA.EDIMENS|PR05|1|
X2967|08/09/2006|23h19|PNEU741M|B8224-PNEU741M|IMSP.EDIMENS|PR05|1|
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201827 20 sept. 2006 à 13:35
Bonjour à tous....
Ci-dessous, la translation de vb6 en vbs du script que m'a proposé PCPT.
Il y a surement plus simple.
Je ne suis pas arrivé à comprendre et, donc, à manipuler, le "aArrayAll".
Ayant valider ce post ("Réponse acceptée"), les nouveaux échanges ne sont plus affichés
dans la rubrique "Derniers échanges", je posterai un nouvel topic pour un tri un peu plus "poussé".
Option Explicit
'Const ForReading 1, ForWriting 2, ForAppending = 8
Dim Path: Path = "D:\OxaJor"
Dim Fichier: Fichier = "enumeration_DPRs.txt"
Dim Fic_Temp: Fic_Temp = Left(Path & Fichier,Len(Path & Fichier)-4) & "_new.txt"
Dim Fso: Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Fic_Entree: Set Fic_Entree = Fso.OpenTextFile(Path & Fichier, 1, False)
Dim Fic_Sortie: Set Fic_Sortie = Fso.OpenTextFile(Fic_Temp, 2, True)
Dim sTmp
Dim i: i = 0
Dim j: j = 0
Do While Not Fic_Entree.AtEndOfStream
sTmp = Split(Replace(Fic_Entree.ReadAll,"|X","X"), vbCrLf) 'création tableau du fichier
'stmp(0) contient la ligne ci-dessous
'X2918|08/09/2006|22h55|ALES860M|B8062-ALES860M|IMSA.EDIMENS|II9X|1|
For i = 0 To UBound(sTmp)
' MsgBox "le plus grand indice disponible pour la dimension indiquée d'un tableau : " & UBound(sTmp) &vbCrLf&_
' "le plus petit indice disponible pour la dimension indiquée d'un tableau : " & LBound(sTmp) &vbCrLf&vbCrLf&_
' "ligne courante : " &vbCrLf& sTmp(i) &vbCrLf&vbCrLf& "indice de la dimension du tableau : " & i,,_
' "Vérification du tableau sTmp"
'
'ReDim Preserve aArrayAll(i)
'aArrayAll(i) = sTmp
'MsgBox "verif sTmp(i): " & sTmp(i) &vbCrLf& "verif UBound aArrayAll: "& UBound(aArrayAll)
Next
i = i + 1
Loop
Fic_Entree.Close
'MsgBox Left(sTmp(0),4)
'
Dim cprovisoire, bpermute
bpermute = True 'Il faut au moins parcourir une fois
Do While bpermute = True 'On tourne tant que l'on bouge des valeurs
bpermute = False
For i = UBound(sTmp) To 1 Step -1
For j = 0 To i - 1
'MsgBox Split(sTmp(j), "|")(6)
If Split(sTmp(j), "|")(6) < Split(sTmp(j + 1), "|")(6) Then
'MsgBox "verif sTmp(j) " &vbCrLf& sTmp(j)
'sTmp = aArrayAll(j)
'aArrayAll(j) = aArrayAll(j + 1)
'aArrayAll(j + 1) = sTmp
cprovisoire = sTmp(j) 'On inverse les deux chaines
sTmp(j) = sTmp(j + 1) 'bis
sTmp(j + 1) = cprovisoire 'bis
bpermute = True
End If
Next
Next
Loop
Dim liste
For i = 0 To UBound(sTmp)
liste = sTmp(i) &vbCrLf& liste
Next
Fic_Sortie.WriteLine liste
Fic_Sortie.Close
Set Fso = Nothing
Set Fic_Entree = Nothing
Set Fic_Sortie = Nothing