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:
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
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 !