Tuto, Moulinette extraire variables

Sous forum réservé aux tutoriaux concernant les produits de la marque Schneider
Avatar de l’utilisateur
itasoft
Mi homme - Mi automate
Mi homme - Mi automate
Messages : 7035
Inscription : 20 oct. 2015, 10:15
Localisation : Lyon
Contact :

Tuto, Moulinette extraire variables

Message par itasoft »

Slts,
Moulinette pour extraire les variables de type %MW de tout fichier ascii (txt)
Procédure :
Copier les lignes de programme ci dessous et les coller dans le Bloc-Notes, enregistrer sous mw.vbs
Avec l’explorateur de fichier Windows double clic gauche sur mw.vbs pour lancer la moulinette.
Résultat dans le fichier_RESULT.TXT ( Pour les autres types modifier %MW[0-9]+ )
------------------------------------------------------------------------------------------------------


Option explicit
Dim TXT,fileNameSource,fileNameCible,sOBJ,sVAL, sL,sSYMB,sSSS
Dim mySize
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") & ".txt"
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 %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 & chr(9) & sOBJ & chr(9) & "INT"
Wtxt.writeline (sSSS)
sL=sL & sVAL
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
Automaticien privé (de tout)
itasoft@free.fr
Avatar de l’utilisateur
RedFish
Générateur de blocs fonctions
Générateur de blocs fonctions
Messages : 140
Inscription : 01 avr. 2016, 09:56
Localisation : BRETAGNE/NORMANDIE

Re: Tuto, Moulinette extraire variables

Message par RedFish »

Merci ;)
Répondre