Cookid Posted September 18, 2018 Posted September 18, 2018 (edited) Okay so i'm really bad at this so I need some help. I've been looking all over to try to find a code that I can edit to process what I need, but I can't find any. I want to convert, lets say, A to "11.", B to "12." and so on, and yes the period is included. But I haven't been able to find out how to do this. So is it possible to do this? It would save tons of time. Edited September 21, 2018 by Cookid Solved
Developers Jos Posted September 18, 2018 Developers Posted September 18, 2018 Something simple like this?: consolewrite( Convert("A") & @crlf) consolewrite( Convert("B") & @crlf) consolewrite( Convert("Z") & @crlf) Func Convert($char) $char=StringUpper($char) $base=11 $A_asc=65 return (asc($char)-$A_asc+$base)&"." EndFunc 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.
Davidowicza Posted September 18, 2018 Posted September 18, 2018 (edited) Another way to convert would be declaring a 2D array first then looping through it to convert your character. Not as simple as Jos example but you can convert any letter to anything you want it to be! #include <Array.au3> #include <String.au3> Global $arr1[26][2] = [["A", "11."], ["B", "12."]] ;ect ect Func Convert($char) For $i = 0 To UBound($arr1) - 1 Step 1 If $char = $arr1[$i][0] Then $char = $arr1[$i][1] Return($char) EndIf Next EndFunc Also, Hi everyone (first post) Edited September 18, 2018 by Davidowicza coding fix
Bert Posted September 18, 2018 Posted September 18, 2018 David is correct - creating an array is the way to go. Jos's approach also works. To put it simply - coding is an art, and a dark art at that. The Vollatran project My blog: http://www.vollysinterestingshit.com/
Cookid Posted September 20, 2018 Author Posted September 20, 2018 (edited) On 9/18/2018 at 2:45 PM, Jos said: Something simple like this?: consolewrite( Convert("A") & @crlf) consolewrite( Convert("B") & @crlf) consolewrite( Convert("Z") & @crlf) Func Convert($char) $char=StringUpper($char) $base=11 $A_asc=65 return (asc($char)-$A_asc+$base)&"." EndFunc Jos This works nice, but by the way it's setup the letters end up getting translated incorrectly, as I said it's very specific and I'm not sure how to adjust it to that. While A and B are correct on there, as 11 and 12, Z would be 56. And I don't think it can be modified correctly with the "StringUpper" fuction. Sorry for how complicated this is. If needed this is all the correct translations: Spoiler A = 11. B = 12. C = 13. D = 14. E = 15. F = 21. G = 22. H = 23. I = 24. J = 25. K = 31. L = 32. M = 33. N = 34. O = 35. P = 41. Q = 42. R = 43. S = 44. T = 45. U = 51. V = 52. W = 53. X = 54. Y = 55. Z = 56. Edited September 20, 2018 by Cookid
Subz Posted September 20, 2018 Posted September 20, 2018 Just use Davids method above, that way you can customize your numbers as required.
Cookid Posted September 20, 2018 Author Posted September 20, 2018 18 minutes ago, Subz said: Just use Davids method above, that way you can customize your numbers as required. Well i've tried using it but I can't get it to output anything else but 0. I've tried stating the "ARRL" as a letter but that doesnt work. Is there a specific thing I have to do for it to pick a letter?
Subz Posted September 20, 2018 Posted September 20, 2018 (edited) Not sure how your coding it but see example here: Global $aConversion[26][2] = [["A", "11."], ["B", "12."], ["C", "13."], ["D", "14."], ["E", "15."], ["F", "21."], ["G", "22."], ["H", "23."], ["I", "24."], ["J", "25."], ["K", "31."], ["L", "32."], ["M", "33."], ["N", "34."], ["O", "35."], ["P", "41."], ["Q", "42."], ["R", "43."], ["S", "44."], ["T", "45."], ["U", "51."], ["V", "52."], ["W", "53."], ["X", "54."], ["Y", "55."], [" Z", "56."]] For $i = 0 To UBound($aConversion) - 1 MsgBox(4096, "Conversion", $aConversion[$i][0] & " = " & Convert($aConversion[$i][0]), 1) Next Func Convert($sChar) For $i = 0 To UBound($aConversion) - 1 Step 1 If $sChar = $aConversion[$i][0] Then $sChar = $aConversion[$i][1] Return($sChar) EndIf Next EndFunc Edited September 20, 2018 by Subz Forgot to add the function doh
Davidowicza Posted September 21, 2018 Posted September 21, 2018 16 hours ago, Cookid said: Well i've tried using it but I can't get it to output anything else but 0. I've tried stating the "ARRL" as a letter but that doesnt work. Is there a specific thing I have to do for it to pick a letter? It'll be easier to help if you post your code if you are still having issues.
Cookid Posted September 21, 2018 Author Posted September 21, 2018 1 hour ago, Davidowicza said: It'll be easier to help if you post your code if you are still having issues. My problem has been fixed. I don't know how to set it as solved though
FrancescoDiMuro Posted September 21, 2018 Posted September 21, 2018 @Cookid Edit the first post, setting in the title "Solved" Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Malkey Posted September 22, 2018 Posted September 22, 2018 This is an exercise in "It can be done". expandcollapse popup; https://www.autoitscript.com/forum/topic/195770-solved-convert-letters-to-specific-numbers/?do=findComment&comment=1403424 Local $iGroupSize = 5 For $i = 65 To 90 ;ConsoleWrite(Chr($i) & " = " & _Alpha2Numeric(Chr($i), 3, 8, 12) & (Mod($i - 64, 8) ? " " : @CRLF)) ConsoleWrite(Chr($i) & " = " & _Alpha2Numeric(Chr($i), 11, $iGroupSize, 10) & (Mod($i - 64, $iGroupSize) ? " " : " <-- a group" & @CRLF)) Next ConsoleWrite(" <-- sequencially carried on from the previous group" & @CRLF) ; Parameters:- ; $char - The character to be converted to a number. ; $base - The starting number for "A". The first character in the first group. ; $iGroupSize - The maximum number of characters in a group. ; $iGroupJump - A number that each group is incremented by. ; Func _Alpha2Numeric($char, $base = 11, $iGroupSize = 5, $iGroupJump = 10) If $iGroupJump < $iGroupSize Then MsgBox(0, "Warning", "Duplicate numbers will be assigned to different letters") $char = StringUpper($char) Local $A_asc = 65 Local $iPosAtEnd = AscW("Z") - Mod(26, $iGroupSize) ; Unicode code of a last character of last whole group (of $iGroupSize size). If AscW($char) > $iPosAtEnd Then _ ; The last incomplete group will sequencially continue on from the second last group of numbers. i.e. $iGroupJump will not be used on the last incomplete group. Return _Alpha2Numeric(ChrW($iPosAtEnd), $base, $iGroupSize, $iGroupJump) + AscW($char) - $iPosAtEnd & "." $Increm = Mod(Asc($char) - $A_asc, $iGroupSize) + $base ; For each group of 5 (or $iGroupSize) numbers, we have: $Increm = Base + (0 to 4) $iFactor = (Int((Asc($char) - $A_asc) / $iGroupSize)) * $iGroupJump ; Every nth group of 5 numbers, multiply by 10 (or $iGroupJump) i.e. (10 * n), where first in group is n = 0. Return $iFactor + $Increm & "." EndFunc ;==>_Alpha2Numeric #cs ; _Alpha2Numeric(Chr($i), 11, 5, 10) returns:- A = 11. B = 12. C = 13. D = 14. E = 15. <-- a group F = 21. G = 22. H = 23. I = 24. J = 25. <-- a group K = 31. L = 32. M = 33. N = 34. O = 35. <-- a group P = 41. Q = 42. R = 43. S = 44. T = 45. <-- a group U = 51. V = 52. W = 53. X = 54. Y = 55. <-- a group Z = 56. <-- sequencially carried on from the previous group _Alpha2Numeric(Chr($i), 3, 8, 12) returns:- A = 3. B = 4. C = 5. D = 6. E = 7. F = 8. G = 9. H = 10. I = 15. J = 16. K = 17. L = 18. M = 19. N = 20. O = 21. P = 22. Q = 27. R = 28. S = 29. T = 30. U = 31. V = 32. W = 33. X = 34. Y = 35. Z = 36. <-- sequencially carried on from the previous group #ce
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