Sign in to follow this  
Followers 0
ZenKensei

For...Next Loop with Letters

5 posts in this topic

Group,

I am looking for some help in dealing with a For...Next Loop using letters instead of numbers (specifically F - Z). I have a script that runs during a network logon that checks entries in an .ini file. Each user can edit the .ini file to include network shares of their choice to drives F through Z. I have the following code which currently works, but I have to duplicate this snippet of code for each drive letter in the .ini file, i.e. F - Z:

$Map = IniRead("Mapmenu.ini", "F-Drive", "Share", "NotFound")
If $Map <>"None" Then
    DriveMapDel ("F:")
    SplashTextOn("Network Drive", "Mapping Drive F: to " & $Map, 450, 90)
    Sleep (1000)
    SplashOff ( )
DriveMapAdd ("F:",$Map)
Endif

It reads an .ini entry similar to the following:

[F-Drive]
Share=\\Server\Share

I thought something similar to the following might work, but I just can't get the For...Next Loop working with letters.

For $i = F to Z Step 1
$Map = IniRead("Mapmenu.ini", $i & "-Drive", "Share", "NotFound")
If $Map <>"None" Then
    DriveMapDel ($i & ":")

Any suggestions, or help would be greatly appreciated.

Thanks

Z/K

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use the ASCII code's. A = 65, Z = 90. The rest of the letters are enumerated between (These are for uppercase).

So...

For $i = 70 To 90
    $Map = IniRead("Mapmenu.ini", Chr($i) & "-Drive", "Share", "NotFound")
    If $Map <>"None" Then DriveMapDel (Chr($i) & ":")
Next
Edited by Valik

Share this post


Link to post
Share on other sites

This can also be accomplished by using an array containing the letters in question.

Dim $tmp, $Letters, $i

$tmp = "F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
$Letters = StringSplit($tmp, ",")

For $i = 1 to $Letters[0]
    $Map = IniRead("Mapmenu.ini", $Letters[$i] & "-Drive", "Share", "NotFound")
    If $Map <>"None" Then DriveMapDel (Letters[$i] & ":")
Next

The only advantage to this method is you can have it skip letters if needed. This is accompished by just skipping them in the string $tmp during initialization.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

Or I might say the following (unless you comment your code as to why you are using the magic numbers 70 and 90):

For $i = Asc("F") To Asc("Z")

;....... Chr($i) ......

Next

(BTW, it's my understanding that the For-loop bounds are only checked once, so it's not inefficient to have the Asc() function call in them.)


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Or I might say the following (unless you comment your code as to why you are using the magic numbers 70 and 90):

For $i = Asc("F") To Asc("Z")

;....... Chr($i) ......

Next

(BTW, it's my understanding that the For-loop bounds are only checked once, so it's not inefficient to have the Asc() function call in them.)

<{POST_SNAPBACK}>

That is correct, this script demonstrates that:

Local $i, $n = 2
For $i = 1 To $n
    TrayTip("", $i & " - " & $n, 5, 16)
    $n = $n + 1
    Sleep(1000)
Next

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