E1M1 Posted October 13, 2010 Share Posted October 13, 2010 (edited) I need to convert number to char. 1=A 26=Z 27=AA By what logic i can convert random int to A-Z string? I cant find any logig. Edited October 13, 2010 by E1M1 edited Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 13, 2010 Moderators Share Posted October 13, 2010 E1Mi, Perhaps something like this: $iInt = InputBox("Enter a Number", "Just a number from 1 to 676") $iSecond = Mod($iInt, 26) $iFirst = Int($iInt / 26) $sLetters = "" If $iFirst > 0 Then $sLetters &= Chr($iFirst + 64) $sLetters &= Chr($iSecond + 64) ConsoleWrite($sLetters & @CRLF) Lots of work for you still to do, but it gives you the idea. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mat Posted October 13, 2010 Share Posted October 13, 2010 Hang on... In theory, you are talking about a numerical base with a letter notation. Base 26 in this case. When you think of it that way, it makes it more logical: Func ToBase26($i) Local $s = "" Do $s = Chr(Mod($i, 26) + 64) & $s $i = Int($i / 26) Until $i = 0 Return $s EndFunc ;==>ToBase26 That was based on WBD's (pity he hasn't been around recently) code here: http://www.autoitscript.com/forum/index.php?showtopic=93742 I'm sure he posted a better version with _FromBase somewhere... Got the link Melba? AutoIt Project Listing Link to comment Share on other sites More sharing options...
UEZ Posted October 13, 2010 Share Posted October 13, 2010 (edited) Something like this?ConsoleWrite(N2C(28) & @CRLF) Func N2C($int) Local $j, $char, $m For $j = 1 To Ceiling($int / 26) $m = Mod($int, 26) If Not $m Then $char &= Chr(90) ;"Z" Else $char &= Chr(64 + $m) EndIf Next Return $char EndFuncBr,UEZ Edited October 13, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
E1M1 Posted October 13, 2010 Author Share Posted October 13, 2010 Func ToBase26($i) Local $s = "" Do $s = Chr(Mod($i, 26) + 64) & $s $i = Int($i / 26) Until $i = 0 Return $s EndFunc ;==>ToBase26 Does anyone know why 26 doesnt return Z wuth this func? all other numbers seems working, just 26 is problematic. UEZ's func also doesn like 26 edited Link to comment Share on other sites More sharing options...
Mat Posted October 13, 2010 Share Posted October 13, 2010 (edited) What would zero be in this base? Think about that for a bit. One possible solution: Func ToBase26($i) Local $s = "" Do $s = Chr(Mod($i, 26) + 64) & $s $i = Int($i / 27) Until $i = 0 Return StringReplace($s, "@", "Z") EndFunc ;==>ToBase26 Edited October 13, 2010 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
UEZ Posted October 13, 2010 Share Posted October 13, 2010 (edited) Indeed, did not keep in mind the 0 base. Update above. Br, UEZ Edited October 13, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
E1M1 Posted October 13, 2010 Author Share Posted October 13, 2010 ok now why 28 is BB and not AB? it should go like aa, ab ac...az ... aaa,aab,aac.... Looks like i didnt express myself clearly enough at the beginning. edited Link to comment Share on other sites More sharing options...
Mat Posted October 13, 2010 Share Posted October 13, 2010 (edited) ok now why 28 is BB and not AB? it should go like aa, ab ac...az ... aaa,aab,aac.... Looks like i didnt express myself clearly enough at the beginning. For mine? Try this: For $i = 1 To 100 ConsoleWrite(ToBase26($i) & @CRLF) Next Func ToBase26($i) Local $s = "" Do $s = Chr(Mod($i, 26) + 64) & $s $i = Int($i / 27) Until $i = 0 Return StringReplace($s, "@", "Z") EndFunc ;==>ToBase26 It's not ideal, but it works. A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU AV AW AX AY AZ AA BB BC BD BE BF BG BH BI BJ BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY BZ BA BB CC CD CE CF CG CH CI CJ CK CL CM CN CO CP CQ CR CS CT CU CV Edited October 13, 2010 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
UEZ Posted October 13, 2010 Share Posted October 13, 2010 ok now why 28 is BB and not AB? it should go like aa, ab ac...az ... aaa,aab,aac....Looks like i didnt express myself clearly enough at the beginning.Yep, I misunderstood you! Sorry,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
E1M1 Posted October 13, 2010 Author Share Posted October 13, 2010 Mat your's code works nicely. Just 1 question. what is mod()? and is it possible to do what mod() does with out mod() ? like using /*-+ instead? edited Link to comment Share on other sites More sharing options...
Developers Jos Posted October 13, 2010 Developers Share Posted October 13, 2010 (edited) Just 1 question. what is mod()? and is it possible to do what mod() does with out mod() ? like using /*-+ instead?What part of the description in the helpfile for this function did you not understand? Edited October 13, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
E1M1 Posted October 13, 2010 Author Share Posted October 13, 2010 (edited) I dont understand mod in general. it takes 2 args, but what it does with them? It's more math related question already. But anyway, thanks for fast replies and what's most important for help. Edited October 13, 2010 by E1M1 edited Link to comment Share on other sites More sharing options...
Developers Jos Posted October 13, 2010 Developers Share Posted October 13, 2010 I dont understand mod in general. it takes 2 args, but what it does with them? It's more math related question already.You didn't answer my question unless it means you didn't bother to read it because you thing it wont answer your question.I think it does or at least gives you the keyword to research further.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Tvern Posted October 13, 2010 Share Posted October 13, 2010 You simulate the behavior of Mod() quite easily. I wouldn't reccomend using these functions though. (untested, but they are likely to be allot slower than Mod().) Func _NotMod($value1, $value2) Return $value1-($value2*Int($value1/$value2)) EndFunc Func _NotMod2($value1, $value2) While $value1 >= $value2 $value1 -= $value2 WEnd Return $value1 EndFunc Link to comment Share on other sites More sharing options...
Mat Posted October 13, 2010 Share Posted October 13, 2010 (edited) Think of your division when you were six. 9 divided by 4 is... 2 remainder 1. Mod returns the 1. Mod(9, 4) = 1 In most languages it's '9 % 4 = 1' or something like that. http://en.wikipedia.org/wiki/Modulo_operation Not to be confused with moderators or people riding vespas. Edited October 13, 2010 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
E1M1 Posted October 13, 2010 Author Share Posted October 13, 2010 (edited) I've read your question, and answered it. As I said I dont understand mod in general. There's no specific part in help file that i dont understand. If you want specific part, i would say Parameters. Thanks Mat. Edited October 13, 2010 by E1M1 edited Link to comment Share on other sites More sharing options...
Developers Jos Posted October 13, 2010 Developers Share Posted October 13, 2010 I've read your question, and answered it. As I said I dont understand mod in general. There's no specific part in help file that i dont understand. If you want specific part, i would say Parameters.geezzz... I am referring to the Mod() function in the helpfile , not the whole damn helpfile.It is properly explained and I have sometimes the impression you take the easy way out and simply ask the question. You are here long enough to sort these trivial things out yourself.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Mat Posted October 13, 2010 Share Posted October 13, 2010 (edited) If it's parameters then think like this: a / b = c remainder d Mod(a, = d Edited October 13, 2010 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
E1M1 Posted October 13, 2010 Author Share Posted October 13, 2010 (edited) And I answered about mod. Maybe I wasn't clear. Instead of There's no specific part in help file that i dont understand. I should have said There's no specific part in mod() documentationthat I dont understand....I guess.How should I express myself if I want to say you that I was reading mod function from help file and there wasn't any specific part in mod's documentation in help file that I didn't understand.. Edited October 13, 2010 by E1M1 edited 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