Slts,
Moulinette gratuite pour extraire les variables (%M,%MW,%MD,%MF) de tout fichier ASCII génère un fichier _RESULT.CSV à ouvrir sur EXCEL
Procédure :
Copier les lignes de programme ci dessous et les coller dans le Bloc-notes enregistrer sous ExtraitVariables.vbs , double clic sur ExtraitVariables.vbs pour lancer la moulinette.
--------------------------------------------------------------------
Option explicit
Dim TXT,fileNameSource,fileNameCible,sOBJ,sVAL, sL,sSYMB,sSSS,sEquipement,sMOT,sBIT
Dim mySize,nbl
Dim FSO,Rtxt,Wtxt
Dim oRegExp, oMatches, oMatch
'Objet Régular-expressions
Set oRegExp = CreateObject("VBScript.RegExp")
oRegExp.Global = True
oRegExp.IgnoreCase = True
fileNameSource=GetFileNameDlg()
if InStr(fileNameSource,".")=0 then
MsgBox("Fichier avec Extension obligatoire ex: *.txt")
WScript.Quit 0
end if
'Fichier résultant avec la liste des variables extraites
fileNameCible = Replace(fileNameSource, ".", "_RESULT_") & ".csv"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Rtxt = FSO.OpenTextFile(fileNameSource)
TXT=Rtxt.ReadAll
Rtxt.close
'Result
Set Wtxt = FSO.createTextFile(fileNameCible,true)
'Extrait les variables %M ---------------------------------------------------
sL=""
oRegExp.Pattern = "%M[0-9]+"
Set oMatches = oRegExp.Execute(TXT)
For Each oMatch In oMatches
'Anti-doublons
sVAL=oMatch.Value & "*"
if instr(sL,sVAL)= 0 then
sSYMB=Replace(oMatch.Value,"%","")
sOBJ=oMatch.Value
sSSS=sSYMB & "," & sOBJ & "," & "EBOOL"
Wtxt.writeline (sSSS)
sL=sL & sVAL
end if
Next
'Extrait les variables %MD -----------------------------------------------------
sL=""
oRegExp.Pattern = "%MD[0-9]+"
Set oMatches = oRegExp.Execute(TXT)
For Each oMatch In oMatches
sVAL=oMatch.Value & "*"
if instr(sL,sVAL)= 0 then
sSYMB=Replace(oMatch.Value,"%","")
sOBJ=oMatch.Value
sSSS=sSYMB & "," & sOBJ & "," & "DINT"
Wtxt.writeline (sSSS)
sL=sL & sVAL
end if
Next
'Extrait les variables %MF --------------------------------------------------------
sL=""
oRegExp.Pattern = "%MF[0-9]+"
Set oMatches = oRegExp.Execute(TXT)
For Each oMatch In oMatches
sVAL=oMatch.Value & "*"
if instr(sL,sVAL)= 0 then
sSYMB=Replace(oMatch.Value,"%","")
sOBJ=oMatch.Value
sSSS=sSYMB & "," & sOBJ & "," & "REAL"
Wtxt.writeline (sSSS)
sL=sL & sVAL
end if
Next
'Extrait les variables %MWx:x ---------------------------------------------------
sL=""
oRegExp.Pattern = "%MW[0-9]+(:X[0-9]+)"
Set oMatches = oRegExp.Execute(TXT)
For Each oMatch In oMatches
sVAL=oMatch.Value & "*"
if instr(sL,sVAL)= 0 then
sSYMB=Replace(oMatch.Value,"%","")
sSYMB=Replace(sSYMB,":X","_")
sOBJ=oMatch.Value
sSSS=sSYMB & "," & sOBJ & "," & "BOOL"
Wtxt.writeline (sSSS)
sL=sL & sVAL
TXT=Replace(TXT,sOBJ,"??")
end if
Next
'Extrait les variables %MWx.x ---------------------------------------------------
sL=""
oRegExp.Pattern = "%MW[0-9]+(\.[0-9]+)"
Set oMatches = oRegExp.Execute(TXT)
For Each oMatch In oMatches
sVAL=oMatch.Value & "*"
if instr(sL,sVAL)= 0 then
sSYMB=Replace(oMatch.Value,"%","")
sSYMB=Replace(sSYMB,".","_")
sOBJ=oMatch.Value
sSSS=sSYMB & "," & sOBJ & "," & "BOOL"
Wtxt.writeline (sSSS)
sL=sL & sVAL
TXT=Replace(TXT,sOBJ,"??")
end if
Next
'Extrait les variables %MW -----------------------------------------------------
sL=""
oRegExp.Pattern = "%MW[0-9]+"
Set oMatches = oRegExp.Execute(TXT)
For Each oMatch In oMatches
sVAL=oMatch.Value & "*"
if instr(sL,sVAL)= 0 then
sSYMB=Replace(oMatch.Value,"%","")
sOBJ=oMatch.Value
sSSS=sSYMB & "," & sOBJ & "," & "INT"
Wtxt.writeline (sSSS)
sL=sL & sVAL
nbl=nbl+1
end if
Next
Wtxt.close
Set oRegExp = Nothing
Set oMatches =Nothing
Set oMatch =Nothing
MsgBox "Fin des opérations" , vbInformation, fileNameCible
Function GetFileNameDlg()
GetFileNameDlg=CreateObject("WScript.Shell").Exec("mshta.exe ""about:<input type=file id=f><script language=""VBScript"">f.click():CreateObject(""Scripting.FileSystemObject"").GetStandardStream(1).Write(f.value):close()</script>""").StdOut.ReadAll
End Function
Moulinette n°33bis
- itasoft
- Mi homme - Mi automate
- Messages : 7037
- Inscription : 20 oct. 2015, 10:15
- Localisation : Lyon
- Contact :
Moulinette n°33bis
Dernière modification par itasoft le 23 sept. 2021, 03:28, modifié 1 fois.
Automaticien privé (de tout)
itasoft@free.fr
itasoft@free.fr
-
- Mi homme - Mi automate
- Messages : 2076
- Inscription : 21 oct. 2015, 10:00
- Localisation : Ile de France
Re: Moulinette n°33bis
Salut !
Merci pour le partage Itasoft !
A mouliner comme ça, sur un vélo tu est maillot jaune !
Merci pour le partage Itasoft !
A mouliner comme ça, sur un vélo tu est maillot jaune !
Si vous avez compris tout ce que je viens d'écrire, c'est que j'ai dû faire une erreur quelque part !