AutoIt-Junky Posted November 19, 2005 Posted November 19, 2005 Hello all!! I was wondering if someone could give me an example of how to use _FileReadToArray properly. I'm trying to string through my scripts and change all my variable names (don't ask why, just a test really). So if my autoit script looked something like this inside: Dim $AutoIt, $IsThe, $Best Func Example() $AutoIt = 1 While 1 If $AutoIt = 1 Then $IsThe = 2 Else $Best = 3 EndIf Wend EndFunc So If I wanted to open the AutoItExample_FR2A.au3 above, I'd like to know how I would go through each line with Strings to modify only the variables with like _StringEncrypt() I've had some really poor turnouts trying it on my own, and I could find nothing for 2 days on the forums to help me with it using _FileReadToArray() other than referring to it. Example of my horrible attempts!! #include <file.au3> #include <STRING.AU3> Dim $File2Array Dim $ReadFile Dim $OutPut $FILE2OPEN = @DeskTopDir & "AutoItExample_FR2A.au3" ;$FILE2COPY = @DeskTopDir & "AutoItExample_FR2A_Copy.au3" If Not _FileReadToArray($FILE2OPEN,$File2Array) Then Exit EndIf ;$FileOpenCopy = FileOpen($FILE2COPY, 2) For $x = 1 to $File2Array[0] For $i = 1 To StringLen($File2Array[$x]) $String = StringMid($File2Array[$x],$i,1) ;;;;MsgBox(0, "$$$", $String) If Asc($String) = 36 Then ;;;MsgBox(0, "FILE", $File2Array[$x]) $String = StringLeft($String, 1) ;;;MsgBox(0, "$$$", $String) If Asc($String) > 47 And Asc($String) < 58 Or Asc($String) > 64 And Asc($String) < 91 Then $OutPut = $OutPut & StringReplace($String, "",_StringEncrypt(1, $String, @UserName)) MsgBox(0, "ENCRYPT", $OutPut) EndIf EndIf Next ;;;FileWriteLine($FileOpenCopy, $OutPut) ;;;MsgBox(0, "ENCRYPT", "$" & $OutPut) If $OutPut <> "" Then $OutPut = "" EndIf Next ;FileClose($FileOpenCopy) I know the example is horrible, I'm just looking for a bit of guidence... the above was just my last attempt among many. Thanks
Francis Lennert (France) Posted November 19, 2005 Posted November 19, 2005 Hello all!! I was wondering if someone could give me an example of how to use _FileReadToArray properly. I'm trying to string through my scripts and change all my variable names (don't ask why, just a test really). So if my autoit script looked something like this inside: Dim $AutoIt, $IsThe, $Best Func Example() $AutoIt = 1 While 1 If $AutoIt = 1 Then $IsThe = 2 Else $Best = 3 EndIf Wend EndFunc So If I wanted to open the AutoItExample_FR2A.au3 above, I'd like to know how I would go through each line with Strings to modify only the variables with like _StringEncrypt() I've had some really poor turnouts trying it on my own, and I could find nothing for 2 days on the forums to help me with it using _FileReadToArray() other than referring to it. Example of my horrible attempts!! #include <file.au3> #include <STRING.AU3> Dim $File2Array Dim $ReadFile Dim $OutPut $FILE2OPEN = @DeskTopDir & "AutoItExample_FR2A.au3" ;$FILE2COPY = @DeskTopDir & "AutoItExample_FR2A_Copy.au3" If Not _FileReadToArray($FILE2OPEN,$File2Array) Then Exit EndIf ;$FileOpenCopy = FileOpen($FILE2COPY, 2) For $x = 1 to $File2Array[0] For $i = 1 To StringLen($File2Array[$x]) $String = StringMid($File2Array[$x],$i,1) ;;;;MsgBox(0, "$$$", $String) If Asc($String) = 36 Then ;;;MsgBox(0, "FILE", $File2Array[$x]) $String = StringLeft($String, 1) ;;;MsgBox(0, "$$$", $String) If Asc($String) > 47 And Asc($String) < 58 Or Asc($String) > 64 And Asc($String) < 91 Then $OutPut = $OutPut & StringReplace($String, "",_StringEncrypt(1, $String, @UserName)) MsgBox(0, "ENCRYPT", $OutPut) EndIf EndIf Next ;;;FileWriteLine($FileOpenCopy, $OutPut) ;;;MsgBox(0, "ENCRYPT", "$" & $OutPut) If $OutPut <> "" Then $OutPut = "" EndIf Next ;FileClose($FileOpenCopy) I know the example is horrible, I'm just looking for a bit of guidence... the above was just my last attempt among many. Thanks Hello, In your example, the _FileReadToArray works perfectly. I have just put a Msgbox after the first loop : For $x = 1 to $File2Array[0] msgbox( 1 ," ?? " ,$File2Array[$x] ) and all the data appears in it... So Your trouble is elsewhere in the $String = StringLeft($String, 1) You have just verify that If Asc($String) = 36 and three lines after you test if $string is Asc($String) > 47 And Asc($String) < 58 Or Asc($String) > 64 And Asc($String) < 91 HTH Francis
AutoIt-Junky Posted November 19, 2005 Author Posted November 19, 2005 Thanks for the reply Francis... If you noticed, I had been using msgbox's to debug that part, so I knew it was going to an array. But, you said what I was looking for, that's exactly where I'm stuck, is the proper way to: Split / Isolate / Change. Thanks Again!
Francis Lennert (France) Posted November 19, 2005 Posted November 19, 2005 (edited) Hello, I send you an exemple where I find the AutoIt Variables in a Script. It's one way to do that ... I'm sure that's not the best but it works. I put all the $Vars in an arrray ... HTH, Francis 2nd Version with the use of Array.au3 (Don't kow why I have written code which exists in UDF !!! ) expandcollapse popup#include <file.au3> #include <STRING.AU3> #include <Array.au3> Dim $File2Array Dim $ReadFile Dim $OutPut Dim $CarOk Dim $IsVariable Dim $Variable Dim $VarListe[1] ; List of the AutoIt Script Variables Dim $NbVar $CarOk = "$_abcdefghijklmnopqrstuvwxyz0123456789" $Y=0 $FILE2OPEN = "c:\aloa.txt" If Not _FileReadToArray($FILE2OPEN,$File2Array) Then Exit EndIf For $x = 1 to $File2Array[0] ; $Len = StringLen($File2Array[$x]) ; For $i = 1 To $Len $String = Stringmid($File2Array[$x],$i,1) If Asc($String) = 36 Then $IsVariable = 1 EndIf If $Isvariable and StringInStr( Stringlower($CarOk) , $String) >0 Then $Variable = $Variable & $String Else if $Variable <> "" Then _ArrayAdd($Varliste , DoWhatIWant($Variable) ) EndIf $IsVariable = 0 $Variable = "" EndIf Next Next _ArrayDisplay( $Varliste ,"Var Liste") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func DoWhatIWant( $Var ) ; I Crypt the Var return $Var EndFunc Edited November 19, 2005 by Francis Lennert (France)
AutoIt-Junky Posted November 20, 2005 Author Posted November 20, 2005 Thanks again Francis... Just a note, I don't know if you know this, but it only reads one variable on the line. So If I have Dim $var1, $var2, it will catch $var1 but not $var2. I had gotten about this far (my code was a bit longer ), but I'm stuck like chuck... Heck, I couldn't even get it to replace the variable name in the script to be edited ($File2Copy) with StringReplace($variable, $variable, _stringencrypt(1, $variable, 1234)).... But, I'll definatelty use yours as a foundation!! Anyone else willing to help, I'd surely appreciate it!!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now