Ma routine prend trop de temps! Réduction!?...

cs_darkbol Messages postés 61 Date d'inscription lundi 7 juin 2004 Statut Membre Dernière intervention 6 décembre 2004 - 23 août 2004 à 09:10
cs_darkbol Messages postés 61 Date d'inscription lundi 7 juin 2004 Statut Membre Dernière intervention 6 décembre 2004 - 23 août 2004 à 10:18
Bonjour,

Est ce que quelqu'un pourrait arranger ma routine de calcul? Comme je suis débutant en VB, j'ai fait à la méthode un peu barbare! voici ladite routine :


Dim Tempo As String

Open Creafold.Dir1.Path & "Surfer Work Data\import Data\Microstation Non Converted Data" & File1.FileName For Input As #1 'opens the file to import im reading mode
Open Creafold.Dir1.Path & "Surfer Work Data\import Data\temp files\tempM.bln" For Output As #2 'opens a temp file for only needed values

Do While Not EOF(1)
       
Line Input #1, Tempo
If Asc(Left$(Tempo, 1)) 67 Or Asc(Left$(Tempo, 1)) 32 Then 'if the first character is "C" or "SPACE"
Print #2, Tempo

End If
Loop

Close #1
Close #2

Open Creafold.Dir1.Path & "Surfer Work Data\import Data\temp files\tempM.bln" For Input As #2
Open Creafold.Dir1.Path & "Surfer Work Data\import Data\temp files\tempM2.bln" For Output As #3 'writes the final file with required pattern

Dim chaine As String
Dim splitage() As String
Dim Splitage1() As String
Dim ChaineInter As String
Dim i As Integer
Dim j As Integer

chaine = StrConv(InputB(LOF(2), 2), vbUnicode) 'returns the file data from temp.bln in one block
splitage() = Split(chaine, "C")

For i = 1 To UBound(splitage()) 'loops on each block splitage()
Splitage1() = Split(splitage(i), vbCrLf) 'splits blocks separated by carriage returns
ChaineInter = ChaineInter & (UBound(Splitage1()) - 1) & vbCrLf 'inserts on the block head the number of values within the block
For j = 1 To UBound(Splitage1()) 'loops on each line
If j = UBound(Splitage1()) Then
ChaineInter = ChaineInter & Splitage1(j)
Else
ChaineInter = ChaineInter & Splitage1(j) & vbCrLf
End If

Next j
Next i

Print #3, ChaineInter

Close #2
Close #3

tronque = Left$(File1.FileName, InStrRev(File1.FileName, ".") - 1)

Open Creafold.Dir1.Path & "Surfer Work Data\import Data\temp files\tempM2.bln" For Input As #1
Open Creafold.Dir1.Path & "Surfer Work Data\import Data\Microstation Converted Data" & tronque & ".bln" For Output As #2 'writes the final file with required pattern
Do While Not EOF(1)
Line Input #1, Tempo

If Not Left$(Tempo, 1) = "-" Then 'if the first character is different of "-"
Print #2, Tempo
End If
Loop

Close #1
Close #2
Stat.Text = "OK!"


MERCI!

PS : Je pense que ca ne changera rien de le préciser mais fo ke je le dise : C ASSEZ URGENT!!! Merci encore!

2 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
23 août 2004 à 09:56
Tu pourrais essayer comme cela...

Option Explicit

Dim Tempo As String
Dim tmp as String
Dim tmpSize as integer

Open Creafold.Dir1.Path & "Surfer Work Data\import Data\Microstation Non Converted Data" & File1.FileName For Input As #1 'opens the file to import im reading mode
Open Creafold.Dir1.Path & "Surfer Work Data\import Data\temp files\tempM.bln" For Output As #2 'opens a temp file for only needed values

Do While Not EOF(1)
DoEvents
Line Input #1, Tempo
If Asc(Tempo) 67 Or Asc(Tempo) 32 Then 'if the first character is "C" or "SPACE"
Print #2, Tempo

End If
Loop

Close #1
Close #2

Open Creafold.Dir1.Path & "Surfer Work Data\import Data\temp files\tempM.bln" For Input As #2
Open Creafold.Dir1.Path & "Surfer Work Data\import Data\temp files\tempM2.bln" For Output As #3 'writes the final file with required pattern

Dim chaine As String
Dim splitage() As String
Dim Splitage1() As String
Dim ChaineInter As String
Dim i As Integer
Dim j As Integer

chaine = StrConv(InputB(LOF(2), 2), vbUnicode) 'returns the file data from temp.bln in one block
splitage() = Split(chaine, "C")

For i = 1 To UBound(splitage()) 'loops on each block splitage()
Splitage1() = Split(splitage(i), vbCrLf) 'splits blocks separated by carriage returns
tmpSize = UBound(Splitage1())
ChaineInter = ChaineInter & (tmpSize - 1) & vbCrLf 'inserts on the block head the number of values within the block
For j = 1 To tmpSize 'loops on each line
tmp = Splitage1(j)
If j = tmpSize Then
ChaineInter = ChaineInter & tmp
Else
ChaineInter = ChaineInter & tmp & vbCrLf
End If

Next j
DoEvents
Next i

Print #3, ChaineInter

Close #2
Close #3

tronque = Left$(File1.FileName, InStrRev(File1.FileName, ".") - 1)

Open Creafold.Dir1.Path & "Surfer Work Data\import Data\temp files\tempM2.bln" For Input As #1
Open Creafold.Dir1.Path & "Surfer Work Data\import Data\Microstation Converted Data" & tronque & ".bln" For Output As #2 'writes the final file with required pattern
Do While Not EOF(1)
DoEvents
Line Input #1, Tempo

If Not Left$(Tempo, 1) = "-" Then 'if the first character is different of "-"
Print #2, Tempo
End If
Loop

Close #1
Close #2
Stat.Text = "OK!"



Amusez-vous ! ;)
Renfield - thomas_reynald@msn.com
Admin CodeS-SourceS
0
cs_darkbol Messages postés 61 Date d'inscription lundi 7 juin 2004 Statut Membre Dernière intervention 6 décembre 2004
23 août 2004 à 10:18
salut !

D'abord merci de m'aider sur deux fronts... hehe

le rafraichissement marche nickel merci mais pr utiliser ma fonction "verifier si mon fichier n'y est pas déja (sendmessage), je dois imbriquer la boucle à l'interieur de mon FOR c ca?

Sinon pour cette routine... ca rame autant, je sais pas si pasuqe jouvre les fichiers et les referme mais c cence convertir un fichier ASCII. Pr 500ko, ca prend 15 sec mais passé un mega, c la fiesta...

A plus!

"j'aime bien faire 2 post en un... :-)"
0
Rejoignez-nous