Zych Posted March 24, 2010 Share Posted March 24, 2010 Hello All, I am just starting to play with AutoIt and find it very interesting. However I cannot find a way to increment a letter. For example, in my script, I want to map some drive letters. I made an ini file that has the starting drive letter. Let's then say I have four mappings to do. So let's say that in my ini file it has the letter "M". So I want to map "M", "N", "O", and "P". How can I increment M to get N? I could not find this in the help guide or through a Google search. Probably pretty easy but not sure how to do it. Thanks, Zych Link to comment Share on other sites More sharing options...
Fulano Posted March 24, 2010 Share Posted March 24, 2010 (edited) You have to cast it to an ascii value and then increment, then switch it back to a character. Keep in mind this will not wrap around from Z to a or z to A, so be sure to do some checks on your data so you don't end up trying to access drive [:\ Chr (Asc ("A") + 1)Edit: Woot! props to Mavis Beacon Edited March 24, 2010 by Fulano Hanukka 1 #fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja! Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 24, 2010 Share Posted March 24, 2010 (edited) You want a numeric value for the letter, which you can get from ASC() or ASCW(). Increment by one with the '+= 1' operator. Then convert back to a letter with Chr() or ChrW(): $sLast = "M" $iASCII = Asc($sLast) $iASCII += 1 $sNext = Chr($iASCII) ConsoleWrite("Next letter = " & $sNext & @LF) That can be shortened, but the longhand method illustrates it better. You would also want some error checking to be sure you didn't go past "Z" and "[" for a mapping letter. Edit: Out-typed by Fulano, but at least we both beat Melba to it! Edited March 24, 2010 by PsaltyDS Lovetobehated 1 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 24, 2010 Moderators Share Posted March 24, 2010 Zych,Welcome to the AuotIt forum. Use Asc to get a numeric representation of the letter and then when you have increased it turn it back into a letter with Chr like this:$sDrive = "M" $iAscDrive = Asc($sDrive) MsgBox(0, "ASCII", "m = " & $iAscDrive) For $i = 1 To 3 MsgBox(0, "Letters", "Next Drive: " & Chr($iAscDrive + $i)) NextAsk if anything is unclear.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...
Zych Posted March 24, 2010 Author Share Posted March 24, 2010 WOW you guys are fast. Thank you very much. Link to comment Share on other sites More sharing options...
Fulano Posted March 24, 2010 Share Posted March 24, 2010 Np, we're kinda weird, playing with code is fun #fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja! 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