tAKTelapis Posted August 29, 2006 Posted August 29, 2006 Hey guys, i use this function a lot, when performing actions on remote computers. computers are named: xxx-Room-01 and so forth. at the moment, whenever i create a For Next statement, i do the following: For $x = 8 to 11 $add0 = StringLen($x) If $add0 = 1 Then $x = String("0"&$x) MsgBox(0, "hellow World", $x) Next is there any way to do this, and use less code ?
Helge Posted August 29, 2006 Posted August 29, 2006 For $x = 8 to 11 MsgBox(0, "hellow World", StringFormat("%02d", $x)) Next
GaryFrost Posted August 29, 2006 Posted August 29, 2006 (edited) Here's one way: For $x = 8 To 11 $add0 = StringFormat("%02d", $x) MsgBox(0, "hellow World", $add0) Next Edit: too slow, Helge beat me to it. Edited August 29, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
Moderators SmOke_N Posted August 29, 2006 Moderators Posted August 29, 2006 (edited) Hey guys, i use this function a lot, when performing actions on remote computers. computers are named: xxx-Room-01 and so forth. at the moment, whenever i create a For Next statement, i do the following: For $x = 8 to 11 $add0 = StringLen($x) If $add0 = 1 Then $x = String("0"&$x) MsgBox(0, "hellow World", $x) Next Edit: That's kind of funny... like a machine going off with answers. Edited August 29, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
tAKTelapis Posted August 29, 2006 Author Posted August 29, 2006 no... we run around 200 last count. but each is in a different lab.. an no lab is over 30.. so 2 digits is fine. thanks for the help guys, i had worked it into one line myself just after asking, i had this: For $x = 8 to 11 If StringLen($x) = 1 Then $x = String("0"&$x) MsgBox(0, "hellow World", $x) Next so i compressed my two lines into one, bu i guess the more proffessional way to go would be the string format. Cheers /tAK
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