Sign in to follow this  
Followers 0
Zych

Increment a Letter

6 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 Posted Image

Edited by Fulano
1 person likes this

#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!

Share this post


Link to post
Share on other sites

#3 ·  Posted (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! :lol:

Edited by PsaltyDS
1 person likes this

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

Share this post


Link to post
Share on other sites

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))

Next

Ask 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

WOW you guys are fast. Thank you very much.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0