BatMan22 Posted October 26, 2018 Share Posted October 26, 2018 Hey guys, so I want to save a file with a random name where the last two letters of the filename are constants, ie 102618AA then 102618AB so on and so forth.. I used the code below to increment a single letter, but what about if I wanted to increment two or three letters, is there any way to do that? $c = Chr(Asc($current) + 1) Link to comment Share on other sites More sharing options...
Subz Posted October 26, 2018 Share Posted October 26, 2018 $c = Chr(Asc($current) + 2) You could just use the above to get the next letter, but don't really understand what your asking? Link to comment Share on other sites More sharing options...
BatMan22 Posted October 26, 2018 Author Share Posted October 26, 2018 No what I guess I mean is.. I need BOTH numbers to 'increment'... ie AZ would increment to BA. Is this possible? Link to comment Share on other sites More sharing options...
Subz Posted October 26, 2018 Share Posted October 26, 2018 You mean something like: #include <Array.au3> _Increment("AZ") _Increment("AZY") Func _Increment($_sString) Local $aString = StringSplit($_sString, "") For $i = 1 To $aString[0] If Asc($aString[$i]) = 90 Then $aString[$i] = Chr(65) Else $aString[$i] = Chr(Asc($aString[$i]) + 1) EndIf Next MsgBox(0,'', _ArrayToString($aString, "", 1)) EndFunc BatMan22 1 Link to comment Share on other sites More sharing options...
iamtheky Posted October 27, 2018 Share Posted October 27, 2018 (edited) edit: i did the same thing @Subz did (a bit lazier), but I didnt spend those 5 minutes to not post it edit2: since ours both reset on asc 90 (back to 65), you would have to ensure the string is uppercase $sIn = StringUpper("ABCXYZ") $sOut = "" $arr = StringToASCIIArray($sIn) For $i = 0 to ubound($arr) - 1 $sOut &= $arr[$i] = 90 ? chr($arr[$i] + 1 - 26) : chr($arr[$i] + 1) Next msgbox(0 , '' , $sOut) Also, check my Gronsfeld Cipher that will let you increment based off an array of values rather than a static number Edited October 27, 2018 by iamtheky BatMan22 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
BatMan22 Posted October 27, 2018 Author Share Posted October 27, 2018 Hmm.. Both are cool but neither is what I need. I was thinking of a function that would increment like AAA...AAB...AAC...AAD....{more increments}....AAZ..ABA.. I mean just like number 001..002..003.. but in letters? Link to comment Share on other sites More sharing options...
Deye Posted October 27, 2018 Share Posted October 27, 2018 (edited) To me this seems to be getting all the combo's Left for you to try .. #include <Array.au3> Local $aMain[0] $str = "" Local $hTimer = TimerInit() For $i = 0 To 25 $0 = 65 + $i $str0 = Chr($0) For $1 = $0 To 90 $str1 = $str0 & Chr($1) For $2 = $0 To 90 $str &= $str1 & Chr($2) & ";" & Chr($2) & $str1 & ";" & Chr($2) & StringReverse($str1) & ";" Next Next Next $a = _ArrayUnique(StringSplit($str, ";", 3)) _ArraySort($a) $a[0] = "Time : " & TimerDiff($hTimer) $a[1] = "Combo Count : " & $a[1] - 1 _ArrayDisplay($a) Deye Edited October 27, 2018 by Deye Speed-Up Touch Link to comment Share on other sites More sharing options...
mikell Posted October 27, 2018 Share Posted October 27, 2018 An easy way could be to use some brute force (as below) to first build your own array, store it in a txt file, then use FileReadToArray when needed and increment using the array index $Form1 = GUICreate("Form1", 150, 310, 200, 100) $List = GUICtrlCreateList("", 20, 20, 110, 250) $label = GUICtrlCreateLabel("Loading ...", 20, 280, 110, 20) GUISetState() $str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Global $text = StringSplit($str, "", 3), $n = 0, $long = 3 _Go(0,"") GUICtrlSetData($label, $n & " solutions") While GUIGetMsg()<>-3 Wend Func _Go($temp, $string) For $i = 0 to UBound($text)-1 If $temp = $long-1 Then GUICtrlSetData($List, $string & $text[$i] & "|") $n += 1 EndIf If $temp < $long-1 Then _Go($temp+1, $string & $text[$i] ) EndIf Next EndFunc BatMan22 and Deye 2 Link to comment Share on other sites More sharing options...
Deye Posted October 27, 2018 Share Posted October 27, 2018 (edited) Updated My example, Since I see i was missing quite a few thousand combos .. Edit: "I was thinking of a function that would increment like AAA...AAB...AAC...AAD....{more increments}....AAZ..ABA.." @ following what you describe 1 to 1 , here is my take .. #include <Array.au3> $sfile = "A" While 1 $str = "" For $1 = 1 To 26 $sfile = Increment($sfile) $str &= $sfile & ";" Next ConsoleWrite($str & @CRLF) If StringLen($sfile) > 3 Then ExitLoop WEnd Func Increment($sfile) If Stringlen <= 2 Then If StringLeft($sfile, 1) = "Z" Then Return "A" & StringTrimLeft($sfile, 1) & "A" EndIf EndIf Local $arr = StringSplit($sfile, "") For $i = UBound($arr) - 1 To 0 Step -1 If Asc(StringRight($arr[$i], 1)) - 89 = 1 Then ContinueLoop $arr[$i] = Chr(Asc($arr[$i]) + 1) If $i < UBound($arr) - 1 Then $arr[$i + 1] = "A" EndIf Return _ArrayToString($arr, "", 1) Next ;~ Return $sfile & "A" EndFunc ;==>Increment Edited October 28, 2018 by Deye Link to comment Share on other sites More sharing options...
Malkey Posted October 28, 2018 Share Posted October 28, 2018 This method converts an alphabetic number to its decimal equivalent and adds one. Then coverts that decimal number to its alphabetic number equivalent. #include <Array.au3> ; Modified functions from https://www.autoitscript.com/forum/topic/194949-array-troubles/?do=findComment&comment=1398101 Local $sNum = "AZZ" MsgBox(0, "", $sNum & " + 1 = " & _Dec2Base26(_Base26ToDec($sNum) + 1) & @CRLF) ; Parameter $iLen - Number of characters in returned string. Func _Dec2Base26($iDec, $iLen = 3) Local $aBase26 = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "", 2) Local $sRet = "" For $i = 0 To Int(Log($iDec) / Log(26)) $sRet = $aBase26[Mod($iDec / 26 ^ $i, 26)] & $sRet Next Return StringRight("AAAAAAAAAAAA" & $sRet, $iLen) EndFunc ;==>_Dec2Base26 Func _Base26ToDec($str) Local $iRet, $a = StringSplit($str, "", 2), $UB = UBound($a) - 1 For $i = 0 To $UB $iRet += 26 ^ ($UB - $i) * (StringInStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", $a[$i], 1) - 1) Next Return $iRet EndFunc ;==>_Base26ToDec BatMan22 and Gianni 2 Link to comment Share on other sites More sharing options...
Deye Posted October 28, 2018 Share Posted October 28, 2018 (edited) Discarding the UnDebugged "If Stringlen <= 2 Then" form my previous post ( left it as unedited for reviewers ..) For other cases that head up to my attention from Malkey's post above, Here is an Update that conducts the suitable approach: #include <Array.au3> MsgBox(0, '', Inc("AYZ")) Func Inc($sStr) Local $sSl = StringTrimRight($sStr, 1) If StringRight($sStr, 1) <> "Z" Then Return $sSl & Chr(Asc(StringRight($sStr, 1)) + 1) Local $sSr = "A" While StringRight($sSl, 1) = "Z" $sSr &= "A" $sSl = StringTrimRight($sSl, 1) WEnd If $sSl = "" Then Return $sSr & "A" $sSr = Chr(Asc(StringRight($sSl, 1)) + 1) & $sSr Return StringTrimRight($sSl, 1) & $sSr EndFunc ;==>Inc Deye Edited October 29, 2018 by Deye BatMan22 1 Link to comment Share on other sites More sharing options...
iamtheky Posted October 28, 2018 Share Posted October 28, 2018 i think this also meets the requirement for 3 letter increments... i have been wronger before tho #include<array.au3> $aValues = stringsplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ" , '' , 2) $str = "XYZ" ;~ $str = "XZZ" $aStr = StringSplit(StringReverse($str) , "" ,2) for $i = 0 to ubound($aStr) - 1 If $aStr[$i] = "Z" Then $aStr[$i] = "A" Else $aStr[$i] = $aValues[_ArraySearch($aValues , $aStr[$i]) + 1] ExitLoop EndIf Next msgbox(0, '' , StringReverse(_ArrayToString($aStr , ""))) BatMan22 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Gianni Posted October 29, 2018 Share Posted October 29, 2018 ....a compact way, it also flags you the overflow. The error flag is setted to 1 if the returned string is in overflow, that is when "ZZZZ" became AAAA. Local $sMyString = "ZZZX" For $i = 1 To 5 $sMyString = _AlphaIncr($sMyString) ConsoleWrite($sMyString & @TAB & (@error ? "<- Overflow!" : "") & @CRLF) Next ; returns the passed string incremented by 1 asc ; set @error on overflow Func _AlphaIncr($sString) Local $sResult = "", $Carry = 1 For $i = StringLen($sString) To 1 Step -1 $sResult = Chr(Mod((Asc(StringMid($sString, $i, 1)) - 65 + $Carry), 26) + 65) & $sResult $Carry = Mod((Asc(StringMid($sString, $i, 1)) + $Carry), 91) <> (Asc(StringMid($sString, $i, 1)) + $Carry) Next Return SetError($Carry, 0, $sResult) EndFunc ;==>_AlphaIncr BatMan22 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
BatMan22 Posted October 29, 2018 Author Share Posted October 29, 2018 Thank you all, you guys all rock, I ended up using what g @Chimp wrote. Turns out four letters is best for what I needed anyways. Thanks all! 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