Jump to content

Enumerate numbers from 01 to 09


Recommended Posts

Helloooooooooo, it's been a while since I coded anything in AutoIt but today I came across a use for it.

Anyway I just need to know if there's anyway I can get AutoIt to enumerate numbers from 01 to 09 instead of 1 to 9.

For example:

For $I = 01 To 50
    ;the first 9 numbers I want prefixed with a 0 and and from there just count normally so...
    ;01, 02, 03, 04, 05, 06, 07, 07, 08, 09, 10, 11, ..., 49, 50
    ;I want to do this because I will be working with strings.
Next

I know how I could work around it by manually adding the 0 for the first nine I'm hoping there's a cleaner way.

Kind regards

~Marlo

Edited by Marlo
Click here for the best AutoIt help possible.Currently Working on: Autoit RAT
Link to comment
Share on other sites

Local $sString
For $I = 1 To 50
    ;the first 9 numbers I want prefixed with a 0 and and from there just count normally so...
    ;01, 02, 03, 04, 05, 06, 07, 07, 08, 09, 10, 11, ..., 49, 50
    ;I want to do this because I will be working with strings.
    $sString &= StringFormat("%02s", $I) & ","
Next
ConsoleWrite(StringTrimRight($sString,1) & @CR)

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

  • 2 weeks later...

You would have to read the contents of the Input control attached to the UpDown, apply the formatting to it, then write back to the input. You can't set it to do that (leading zeroes) without intervention:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $input, $updown, $msg, $sData

GUICreate("My GUI UpDown", -1, -1, -1, -1, $WS_SIZEBOX)

$input = GUICtrlCreateInput("2", 10, 10, 100, 20)
$updown = GUICtrlCreateUpdown($input)
GUISetState()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case Else
            If $sData <> GUICtrlRead($input) Then
                $sData = GUICtrlRead($input)
                $sData = StringFormat("%03d", $sData)
                GUICtrlSetData($input, $sData)
            EndIf
    EndSwitch
WEnd

MsgBox(0, "Updown", GUICtrlRead($input))

:idea:

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...