[Resolved] How to write a LogFile for combination of strings

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
hackoo
Posts: 103
Last visit: Tue Apr 26, 2016 9:02 am

[Resolved] How to write a LogFile for combination of strings

Post by hackoo »

Hi !
I have this code for combination of strings like that : The string entered by the user "abc" the program will return a list of all possible combinations of the string:

abc
acb
bac
bca
cab
cba
So this code works great and show me the correct result that what i need in the MsgBox ,but, when i tried to write it in a LogFile it return to me a result like that :

abc
acb
bac
bca
cab
cba
abc
acb
bac
bca
cab
cba
VBScript Code
Double-click the code block to select all.
Option Explicit
Dim MyStr,Titre,fso,ws,LogFile,resultat
Titre = "Combinaison de chaînes de caractères"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("Wscript.Shell")
'Nom du fichier qui va stocker le résultat
LogFile = Left(Wscript.ScriptFullName,InstrRev(Wscript.ScriptFullName, ".")) & "txt"
if fso.FileExists(LogFile) Then 'Si le fichier LogFile existe
    fso.DeleteFile LogFile 'alors on le supprime
end If
'La boîte de saisie de la chaîne de caractères
MyStr = inputbox("Entrez la chaîne de caractères :",Titre,"abc")
MyStr = Trim(MyStr) 'Pour enlever les espaces de gauche et à droite
If MyStr = "" Then WScript.Quit
MsgBox Traitement("",MyStr),64,Titre
WriteLog String(70,"*"),LogFile
WriteLog Space(10) & Titre & " de type " & DblQuote(MyStr),LogFile
WriteLog String(70,"*"),LogFile
WriteLog Traitement("",MyStr),LogFile
ws.Run LogFile,1,False

Function Traitement(chaine,liste)
    Dim nouvelle_chaine,nouvelle_liste,j
    If liste = "" Then
        resultat = resultat & chaine & VbcrLF
    Else
        For j=1 to Len(liste)
            nouvelle_chaine = chaine & Mid(liste,j,1)
            nouvelle_liste = Replace(liste,Mid(liste,j,1),"")
            Traitement nouvelle_chaine,nouvelle_liste
            nouvelle_chaine = ""
            nouvelle_liste = ""
        Next
    End If   
    Traitement = resultat
End Function
'*****************************************************************
'Fonction pour écrire le résultat dans un fichier texte
Sub WriteLog(strText,LogFile)
    Dim fs,ts
    Const ForAppending = 8
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile(LogFile,ForAppending,True)
    ts.WriteLine strText
    ts.Close
End Sub
'*****************************************************************
'Fonction pour ajouter des guillemets dans une variable
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'*****************************************************************
So How to correct this issue ?
Thank you !
Last edited by hackoo on Sat Sep 28, 2013 7:33 am, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to write a LogFile for combination of strings ?

Post by jvierra »

Your code does not work at all.
User avatar
hackoo
Posts: 103
Last visit: Tue Apr 26, 2016 9:02 am

Re: How to write a LogFile for combination of strings ?

Post by hackoo »

Hi !
Ok i found my mistake !
So i correct it like that :
VBScript Code
Double-click the code block to select all.
Option Explicit
Dim MyStr,Titre,fso,ws,LogFile,resultat
Titre = "Combinaison de chaînes de caractères"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("Wscript.Shell")
'Nom du fichier qui va stocker le résultat
LogFile = Left(Wscript.ScriptFullName,InstrRev(Wscript.ScriptFullName, ".")) & "txt"
if fso.FileExists(LogFile) Then 'Si le fichier LogFile existe
    fso.DeleteFile LogFile 'alors on le supprime
end If
'La boîte de saisie de la chaîne de caractères
MyStr = inputbox("Entrez la chaîne de caractères :",Titre,"abc")
MyStr = Trim(MyStr) 'Pour enlever les espaces de gauche et à droite
If MyStr = "" Then WScript.Quit
MsgBox Traitement("",MyStr),64,Titre
WriteLog String(70,"*"),LogFile
WriteLog Space(10) & Titre & " de type " & DblQuote(MyStr),LogFile
WriteLog String(70,"*"),LogFile
'On réinitialise notre variable globale "resultat" pour ne pas la cumuler dans le fichier LogFile
resultat = ""
WriteLog Traitement("",MyStr),LogFile
ws.Run LogFile,1,False

Function Traitement(chaine,liste)
    Dim nouvelle_chaine,nouvelle_liste,j
    If liste = "" Then
        resultat = resultat & chaine & VbcrLF
    Else
        For j=1 to Len(liste)
            nouvelle_chaine = chaine & Mid(liste,j,1)
            nouvelle_liste = Replace(liste,Mid(liste,j,1),"")
            Traitement nouvelle_chaine,nouvelle_liste
            nouvelle_chaine = ""
            nouvelle_liste = ""
        Next
    End If   
    Traitement = resultat
End Function
'*****************************************************************
'Fonction pour écrire le résultat dans un fichier texte
Sub WriteLog(strText,LogFile)
    Dim fs,ts
    Const ForAppending = 8
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile(LogFile,ForAppending,True)
    ts.WriteLine strText
    ts.Close
End Sub
'*****************************************************************
'Fonction pour ajouter des guillemets dans une variable
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'*****************************************************************
This topic is 10 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked