gazeranco Posted May 2, 2012 Share Posted May 2, 2012 Hey Guys, I want to use like an Int variable and I need it to work like this. Dim Int $myint = (01) $my int +1 Write my int, and I want the value to be = "02" not 2, then 03, 04, 05 etc as it increments. Is this possible? Thanks! Link to comment Share on other sites More sharing options...
stormbreaker Posted May 2, 2012 Share Posted May 2, 2012 Not possible with Int(), since it returns an integer to lowest no. of digits. You could try the following approach: Global $int = 0 Func SomeFunc() While 1 $int = $int + 1 $result = "0" & String($int) Return $result WEnd EndFunc ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
gazeranco Posted May 2, 2012 Author Share Posted May 2, 2012 Thanks! I think that works up to 09, then I will end up with 010 instead of 10? Need some way of changing when I hit 09 I think? Link to comment Share on other sites More sharing options...
water Posted May 2, 2012 Share Posted May 2, 2012 You mix up two things. The internal representation as an integer. Here you don't need to format the number as 01 etc. The presentation of the number for output. Here you need to format the number to your liking. Use StringFormat.ConsoleWrite(StringFormat("%02i", 1) & @CRLF)should give you "01". My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki  Link to comment Share on other sites More sharing options...
stormbreaker Posted May 2, 2012 Share Posted May 2, 2012 Thanx a lot. Lots to learn. ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
water Posted May 2, 2012 Share Posted May 2, 2012 I know. That's how I started too many years ago My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki  Link to comment Share on other sites More sharing options...
gazeranco Posted May 2, 2012 Author Share Posted May 2, 2012 Man im confused! lol Link to comment Share on other sites More sharing options...
gazeranco Posted May 2, 2012 Author Share Posted May 2, 2012 Can you guys help me out with this also, same script I am working with! I am trying to find each instance of "(??)" in a text file and replace it with 1, 2, 3, 4 so on so forth... But the code I have mashed together is only replacing all instances of "(??)" with "1" then it moves on to the next file, can you help?? Cheers! #include <File.au3> ;Local $filer = FileOpen("text.txt", 0) ; Start finding files for writing. ; Shows the filenames of all files in the current directory Local $search = FileFindFirstFile("*.spf*") ;Global $Array ;Local $line = FileRead($filer) ; reads the entire file at one time ;$Text &= $line ; adds the file to the $Text variable which contains the number 3 and a line feed ;$Array[$Array[0]] = $Text ; to this $Array[$Array[0] - 1] = $Text $myint = int(1) While 1 Local $File = FileFindNextFile($search) If @error Then ExitLoop ;$szFile = "c:file.txt" $Text = FileRead($File,FileGetSize($File)) $Text = StringReplace($Text, "(??)", ($myint)) $myint = $myint + 1 FileDelete($File) FileWrite($File,$Text) MsgBox(0, "Search", ($search)) MsgBox(0, "File", ($search)) WEnd ; Close the search handle mofo ;FileClose($filer) FileClose($search) Link to comment Share on other sites More sharing options...
gazeranco Posted May 2, 2012 Author Share Posted May 2, 2012 Just tried editing it like this but still no joy #include <File.au3> Local $search = FileFindFirstFile("*.spf*") $myint = Int(1) While 1 Local $File = FileFindNextFile($search) If @error Then ExitLoop While 2 Local $line = FileReadLine($File) If @error = -1 Then ExitLoop $line = FileReadLine($File) $line = StringReplace($line, "(??)", ($myint)) WEnd $myint = $myint + 1 WEnd ;FileDelete($File) ;FileWrite($File,$Text) ; Close the search handle mofo ;FileClose($filer) FileClose($search) Thanks for looking guys! Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 2, 2012 Share Posted May 2, 2012 #Region ;************ Includes ************ #Include <Array.au3> #EndRegion ;************ Includes ************ $content = FileRead('test.txt1') $found_A = StringRegExp($content, '(??)', 3) _ArrayDisplay($found_A) For $i = 1 To UBound($found_A) $content = StringReplace($content, '(??)', $i, 1) Next MsgBox(0, 'Test', $content) ; Insted of this use FileWrite Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
gazeranco Posted May 2, 2012 Author Share Posted May 2, 2012 Thanks xeno! The arraydisplay works and shows me the instances of (??) but when I try and save the new results it's the same? I have to be honest your code is way above me as I am a little new to this stuff :s #Region ;************ Includes ************ #Include <Array.au3> #EndRegion ;************ Includes ************ $file = ('7377A.spf') $content = FileRead($file) $found_A = StringRegExp($content, '(??)', 3) _ArrayDisplay($found_A) For $i = 1 To UBound($found_A) $content = StringReplace($content, '(??)', $i, 1) Next FileWrite($file, $content) Link to comment Share on other sites More sharing options...
gazeranco Posted May 2, 2012 Author Share Posted May 2, 2012 So I have this now... but still no joy #include <File.au3> #include <Array.au3> Local $search = FileFindFirstFile("*.spf*") $myint = Int(1) While 1 Local $File = FileFindNextFile($search) If @error Then ExitLoop $content = FileRead($File) $found_A = StringRegExp($content, '(??)', 3) _ArrayDisplay($found_A) For $i = 1 To UBound($found_A) $content = StringReplace($content, '(??)', $i, 1) Next $myint = $myint + 1 WEnd FileDelete($File) FileWrite($File,$content) FileClose($search) Link to comment Share on other sites More sharing options...
stormbreaker Posted May 2, 2012 Share Posted May 2, 2012 You have assigned two values to a single variable $content - FileRead() and StringReplace(), and definitely, you won't have joy... ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
gazeranco Posted May 2, 2012 Author Share Posted May 2, 2012 Damn I am struggling to understand this one :-s #include <File.au3> #include <Array.au3> Local $search = FileFindFirstFile("*.spf*") $myint = Int(1) While 1 Local $File = FileFindNextFile($search) If @error Then ExitLoop $content = FileRead($File) $found_A = StringRegExp($content, '(??)', 3) _ArrayDisplay($found_A) For $i = 1 To UBound($found_A) $replace = StringReplace($content, "(??)", $i, 1) Next $myint = $myint + 1 WEnd FileDelete($File) msgbox(0, "content", ($content)) FileWrite($File,$content) FileClose($search) Link to comment Share on other sites More sharing options...
stormbreaker Posted May 2, 2012 Share Posted May 2, 2012 I'll help you since I am bored now. Check this out: StringReplace(FileRead("myfile.txt"), "??", "??") For $i = 1 to @extended StringReplace(FileRead("myfile.txt"), "??", StringFormat("%02i", Int($i)), $i) Next ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
gazeranco Posted May 2, 2012 Author Share Posted May 2, 2012 Sorry for being such a noob! I will get there eventually! This is what I tried but nothing happens. #include <File.au3> #include <Array.au3> Local $search = FileFindFirstFile("*.spf*") $myint = Int(1) While 1 Local $File = FileFindNextFile($search) If @error Then ExitLoop StringReplace(FileRead($File), "(??)", "(??)") For $i = 1 to @extended StringReplace(FileRead($File), "(??)", StringFormat("(%02i)", Int($i)), $i) Next $myint = $myint + 1 WEnd FileDelete($File) FileClose($search) Seprately, this works in that it replaces every instance of (??) with "1" But then I can't implement the loop through files and again increment the number 1... #include <File.au3> Local $int = int(1) Local $find = "(??)" Local $replace = ($int) Local $filename = "7377A.spf" Local $retval = _ReplaceStringInFile($filename, $find, $replace) Link to comment Share on other sites More sharing options...
gazeranco Posted May 2, 2012 Author Share Posted May 2, 2012 Is it possible to loop through the files and lines? or am I trying to do something that I can't with autoit? Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 2, 2012 Share Posted May 2, 2012 Do you really to find ?? or do you want to increase numbers in that files by 1? #Region ;************ Includes ************ #Include <Array.au3> #EndRegion ;************ Includes ************ Global $beforeFilePath = 'test.txt1' Global $afterFilePath = 'test.txt2' Global $content = FileRead($beforeFilePath) Global $found_A = StringRegExp($content, '(??)', 3) ;~ _ArrayDisplay($found_A) For $i = 1 To UBound($found_A) $content = StringReplace($content, '(??)', $i, 1) Next FileWrite($afterFilePath, $content) ShellExecute(@SystemDir & 'notepad.exe', $afterFilePath) Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
gazeranco Posted May 2, 2012 Author Share Posted May 2, 2012 Hey Guys, Ideally I would like to get this code to work as I understand it. #include <File.au3> MsgBox(0, "Running", "The program will prompt you when it has finished!") Local $search = FileFindFirstFile("*.spf*") If $search = -1 Then MsgBox(0, "Error", "Problem finding files!!") Exit EndIf ; $myint = int(1) ; While 1 ; Local $file = FileFindNextFile($search) If @error Then ExitLoop $Text = FileRead($File) $Text = StringReplace($Text, "(??)", ($myint)) FileDelete($File) FileWrite($File,$Text) $myint = $myint + 1 ; WEnd MsgBox(0, "Done", "The script has stopped and your files are edited!") FileClose($search) So it does loop through all my files, but before $myint gets incremented it has already replaced all the instances in 1 file, beuase the next file it replaces them all with 2 instead of 1. So this is almost perfect for me, I just need it to count up after each instance of (??) not after each file. Does this make sense?? Thanks for your input guys! Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 2, 2012 Share Posted May 2, 2012 Try this. It loops through all your files and replaces the ?? by a number. The counts still up even if there is a new file. #region ;************ Includes ************ #include <File.au3> #include <Array.au3> #endregion ;************ Includes ************ Local $FileList = _FileListToArray(@ScriptDir, '*.spf') _ArrayDisplay($FileList) ; show all files in that directory with filter *spf Local $count = 1 For $y = 1 To UBound($FileList) - 1 $content = FileRead(@ScriptDir & '' & $FileList[$y]) $found_A = StringRegExp($content, '(??)', 3) For $i = 0 To UBound($found_A) - 1 $content = StringReplace($content, '(??)', $count + $i, 1) Next $count += UBound($found_A) FileWrite(FileOpen(@ScriptDir & 'NEW' & $FileList[$y], 10), $content) Next ShellExecute(@SystemDir & 'notepad.exe', @ScriptDir & 'NEW' & $FileList[2]) ; See first file as example Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
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