Jump to content

how to increment a varible with different options


tsue
 Share

Recommended Posts

hello, im trying to make a links, automatically with an increasing number, but i have to set some options in some of the links example

link1.html link2.html link3.html ..... link11.htmñ (normal number increasing)

link01.html link02.html link03.html..... link11.html (number increasing with one zero)

link001.html link002.html link003.html .... link011.html .... link111.html (number increasing with two zero)

im having trouble with the third one here is my code

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\luis\Desktop\incremento.kxf
$Form1 = GUICreate("Form1", 621, 500, 192, 124)
$texruta = GUICtrlCreateInput("", 104, 24, 489, 21)
$texlimite = GUICtrlCreateInput("", 104, 56, 33, 21)
$check1 = GUICtrlCreateCheckbox("01", 152, 56, 33, 17)
$check2 = GUICtrlCreateCheckbox("001", 192, 56, 33, 17)
$check3 = GUICtrlCreateCheckbox("0001", 232, 56, 41, 17)
$texrutafinal = GUICtrlCreateInput("", 104, 88, 185, 21)
$iniciar = GUICtrlCreateButton("iniciar", 24, 128, 75, 25, $WS_GROUP)
$Limpiar = GUICtrlCreateButton("Limpiar", 112, 128, 75, 25, $WS_GROUP)
$Edit1 = GUICtrlCreateEdit("", 24, 168, 569, 297)
$Limitefinal = GUICtrlCreateLabel("Incrementador", 24, 64, 72, 17)
$Rutainicial = GUICtrlCreateLabel("Ruta Inicial", 24, 32, 57, 17)
$Rutafinal = GUICtrlCreateLabel("Ruta Final", 24, 96, 52, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


;HotKeySet("k","start")
$j = ""
$k = ""
$l = ""

;notas lo k se ponga en folder drive y drivea va a cambiar a input1,2 y 3 respectivamente
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit

        Case $check1
            If BitAnd(GUICtrlRead($check1),$GUI_CHECKED) = $GUI_CHECKED then
            GUICtrlSetState ($check2, $GUI_UNCHECKED)
            GUICtrlSetState ($check3, $GUI_UNCHECKED)
            $j = 0
            $k = ""
            $l = ""
        Else
            $j = ""
            $k = ""
            $l = ""
        EndIf

        Case $check2
        If BitAnd(GUICtrlRead($check2),$GUI_CHECKED) = $GUI_CHECKED then
            GUICtrlSetState ($check1, $GUI_UNCHECKED)
            GUICtrlSetState ($check3, $GUI_UNCHECKED)
            $j = 0
            $k = 0
            $l = ""
        Else
            $j = ""
            $k = ""
            $l = ""
        EndIf

        Case $check3
        If BitAnd(GUICtrlRead($check3),$GUI_CHECKED) = $GUI_CHECKED then
            GUICtrlSetState ($check2, $GUI_UNCHECKED)
            GUICtrlSetState ($check1, $GUI_UNCHECKED)
            $j = 0
            $k = 0
            $l = 0
        Else
            $j = ""
            $k = ""
            $l = ""
        EndIf



        Case $iniciar
            ;$iniciar = GUICtrlCreateButton("press k in workspace", 296, 64, 75, 25, $WS_GROUP)
            ;Func start()
                For $i = 0 to GUICtrlRead($texlimite, 1)

                    ;case BitAnd(GUICtrlRead($check1),$GUI_CHECKED) = $GUI_CHECKED then $i = 0 & $i
                    ;If BitAnd(GUICtrlRead($check2),$GUI_CHECKED) = $GUI_CHECKED then $i = 0 & 0 & $i
                    ;If BitAnd(GUICtrlRead($check3),$GUI_CHECKED) = $GUI_CHECKED then $i = 0 &0 & 0 & $i
                    ;If $texlimite < 10 Then $i = $j & $i
                    ;If $texlimite < 100 Then $i = $j & $k & $i
                    If $texlimite < 10 Then $i = $j & $k & $l & $i

                    ;If $i < 1000 Then $i = $j & $k & $l & $i

                    $input = GUICtrlRead($texruta, 1)
                    $input2 = $i
                    ;$input2 = GUICtrlRead($i, 1)
                    $input3 = GUICtrlRead($texrutafinal, 1)
                    GUICtrlSetData($Edit1, $input & $input2 & $input3 & @CRLF, 1)

                    ;send ($input & $input2 & $input3)
                Next
            ;EndFunc
        Case $Limpiar
            GUICtrlSetData($Edit1, "")

EndSwitch
WEnd
Link to comment
Share on other sites

Link to comment
Share on other sites

Take a look at the StringFormat() function, switch according to your needs...

For $i = 1 to 10
    ConsoleWrite("link_" & $i & ".html" & @crlf)
Next
For $i = 1 to 10
    ConsoleWrite("link_" & StringFormat("%02s", $i) & ".html" & @crlf)
Next
For $i = 1 to 10
    ConsoleWrite("link_" & StringFormat("%03s", $i) & ".html" & @crlf)
Next

wow thanks it worked, here is the code

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\luis\Desktop\incremento.kxf
$Form1 = GUICreate("Incrementor", 621, 500, 192, 124)
$texruta = GUICtrlCreateInput("", 104, 24, 489, 21)
$texlimite = GUICtrlCreateInput("", 104, 56, 33, 21)
$check1 = GUICtrlCreateCheckbox("01", 152, 56, 33, 17)
$check2 = GUICtrlCreateCheckbox("001", 192, 56, 33, 17)
$check3 = GUICtrlCreateCheckbox("0001", 232, 56, 41, 17)
$texrutafinal = GUICtrlCreateInput("", 104, 88, 185, 21)
$iniciar = GUICtrlCreateButton("iniciar", 24, 128, 75, 25, $WS_GROUP)
$Limpiar = GUICtrlCreateButton("Limpiar", 112, 128, 75, 25, $WS_GROUP)
$Edit1 = GUICtrlCreateEdit("", 24, 168, 569, 297)
$Limitefinal = GUICtrlCreateLabel("Incrementador", 24, 64, 72, 17)
$Rutainicial = GUICtrlCreateLabel("Ruta Inicial", 24, 32, 57, 17)
$Rutafinal = GUICtrlCreateLabel("Ruta Final", 24, 96, 52, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###




While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit

        Case $check1
            If BitAnd(GUICtrlRead($check1),$GUI_CHECKED) = $GUI_CHECKED then
            GUICtrlSetState ($check2, $GUI_UNCHECKED)
            GUICtrlSetState ($check3, $GUI_UNCHECKED)
        EndIf

        Case $check2
        If BitAnd(GUICtrlRead($check2),$GUI_CHECKED) = $GUI_CHECKED then
            GUICtrlSetState ($check1, $GUI_UNCHECKED)
            GUICtrlSetState ($check3, $GUI_UNCHECKED)
        EndIf

        Case $check3
        If BitAnd(GUICtrlRead($check3),$GUI_CHECKED) = $GUI_CHECKED then
            GUICtrlSetState ($check2, $GUI_UNCHECKED)
            GUICtrlSetState ($check1, $GUI_UNCHECKED)
        EndIf



        Case $iniciar
                For $i = 0 to GUICtrlRead($texlimite, 1)

                    If BitAnd(GUICtrlRead($check1),$GUI_CHECKED) = $GUI_CHECKED then $input2 = StringFormat("%02s", $i)
                    If BitAnd(GUICtrlRead($check2),$GUI_CHECKED) = $GUI_CHECKED then $input2 = StringFormat("%03s", $i)
                    If BitAnd(GUICtrlRead($check3),$GUI_CHECKED) = $GUI_CHECKED then $input2 = StringFormat("%04s", $i)
                    If BitAnd(GUICtrlRead($check1),$GUI_UNCHECKED) = $GUI_UNCHECKED and BitAnd(GUICtrlRead($check2),$GUI_UNCHECKED) = $GUI_UNCHECKED and BitAnd(GUICtrlRead($check3),$GUI_UNCHECKED) = $GUI_UNCHECKED then $input2 =  $i


                    $input = GUICtrlRead($texruta, 1)
                    ;$input2 = $i
                    ;$input2 = GUICtrlRead($i, 1)
                    $input3 = GUICtrlRead($texrutafinal, 1)
                    GUICtrlSetData($Edit1, $input & $input2 & $input3 & @CRLF, 1)

                Next

        Case $Limpiar
            GUICtrlSetData($Edit1, "")

EndSwitch
WEnd

one morething, do you know how can i use less code, specially in this part of the code, i think i make a lot of unnecesary coding. thanks

For $i = 0 to GUICtrlRead($texlimite, 1)

                    If BitAnd(GUICtrlRead($check1),$GUI_CHECKED) = $GUI_CHECKED then $input2 = StringFormat("%02s", $i)
                    If BitAnd(GUICtrlRead($check2),$GUI_CHECKED) = $GUI_CHECKED then $input2 = StringFormat("%03s", $i)
                    If BitAnd(GUICtrlRead($check3),$GUI_CHECKED) = $GUI_CHECKED then $input2 = StringFormat("%04s", $i)
                    If BitAnd(GUICtrlRead($check1),$GUI_UNCHECKED) = $GUI_UNCHECKED and BitAnd(GUICtrlRead($check2),$GUI_UNCHECKED) = $GUI_UNCHECKED and BitAnd(GUICtrlRead($check3),$GUI_UNCHECKED) = $GUI_UNCHECKED then $input2 =  $i


                    $input = GUICtrlRead($texruta, 1)
                    ;$input2 = $i
                    ;$input2 = GUICtrlRead($i, 1)
                    $input3 = GUICtrlRead($texrutafinal, 1)
                    GUICtrlSetData($Edit1, $input & $input2 & $input3 & @CRLF, 1)

                Next
Link to comment
Share on other sites

Defining a 1-line mini function helps to clean it up (messed up your code indentation though, sorry)

#include 
#include 
#include 
#include 
#include 
#Region ### START Koda GUI section ### Form=C:\Users\luis\Desktop\incremento.kxf
$Form1 = GUICreate("Incrementor", 621, 500, 192, 124)
$texruta = GUICtrlCreateInput("", 104, 24, 489, 21)
$texlimite = GUICtrlCreateInput("", 104, 56, 33, 21)
$check1 = GUICtrlCreateCheckbox("01", 152, 56, 33, 17)
$check2 = GUICtrlCreateCheckbox("001", 192, 56, 33, 17)
$check3 = GUICtrlCreateCheckbox("0001", 232, 56, 41, 17)
$texrutafinal = GUICtrlCreateInput("", 104, 88, 185, 21)
$iniciar = GUICtrlCreateButton("iniciar", 24, 128, 75, 25, $WS_GROUP)
$Limpiar = GUICtrlCreateButton("Limpiar", 112, 128, 75, 25, $WS_GROUP)
$Edit1 = GUICtrlCreateEdit("", 24, 168, 569, 297)
$Limitefinal = GUICtrlCreateLabel("Incrementador", 24, 64, 72, 17)
$Rutainicial = GUICtrlCreateLabel("Ruta Inicial", 24, 32, 57, 17)
$Rutafinal = GUICtrlCreateLabel("Ruta Final", 24, 96, 52, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###




While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $check1
            If IsChecked($check1) then
            GUICtrlSetState ($check2, $GUI_UNCHECKED)
            GUICtrlSetState ($check3, $GUI_UNCHECKED)
            EndIf

        Case $check2
            If IsChecked($check2) then
            GUICtrlSetState ($check1, $GUI_UNCHECKED)
            GUICtrlSetState ($check3, $GUI_UNCHECKED)
            EndIf

        Case $check3
            If IsChecked($check3) then
            GUICtrlSetState ($check2, $GUI_UNCHECKED)
            GUICtrlSetState ($check1, $GUI_UNCHECKED)
            EndIf

        Case $iniciar
            For $i = 0 to GUICtrlRead($texlimite, 1)
            If IsChecked($check1) then $input2 = StringFormat("%02s", $i)
            If IsChecked($check2) then $input2 = StringFormat("%03s", $i)
            If IsChecked($check3) then $input2 = StringFormat("%04s", $i)
            If IsChecked($check1) and IsChecked($check2) and IsChecked($check3) then $input2 =  $i
            $input = GUICtrlRead($texruta, 1)
                ;$input2 = $i
                ;$input2 = GUICtrlRead($i, 1)
                $input3 = GUICtrlRead($texrutafinal, 1)
                GUICtrlSetData($Edit1, $input & $input2 & $input3 & @CRLF, 1)
            Next

          Case $Limpiar
            GUICtrlSetData($Edit1, "")
   EndSwitch
WEnd


Func IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED)  
EndFunc   ;==>IsChecked
Link to comment
Share on other sites

Defining a 1-line mini function helps to clean it up (messed up your code indentation though, sorry)

#include 
#include 
#include 
#include 
#include 
#Region ### START Koda GUI section ### Form=C:\Users\luis\Desktop\incremento.kxf
$Form1 = GUICreate("Incrementor", 621, 500, 192, 124)
$texruta = GUICtrlCreateInput("", 104, 24, 489, 21)
$texlimite = GUICtrlCreateInput("", 104, 56, 33, 21)
$check1 = GUICtrlCreateCheckbox("01", 152, 56, 33, 17)
$check2 = GUICtrlCreateCheckbox("001", 192, 56, 33, 17)
$check3 = GUICtrlCreateCheckbox("0001", 232, 56, 41, 17)
$texrutafinal = GUICtrlCreateInput("", 104, 88, 185, 21)
$iniciar = GUICtrlCreateButton("iniciar", 24, 128, 75, 25, $WS_GROUP)
$Limpiar = GUICtrlCreateButton("Limpiar", 112, 128, 75, 25, $WS_GROUP)
$Edit1 = GUICtrlCreateEdit("", 24, 168, 569, 297)
$Limitefinal = GUICtrlCreateLabel("Incrementador", 24, 64, 72, 17)
$Rutainicial = GUICtrlCreateLabel("Ruta Inicial", 24, 32, 57, 17)
$Rutafinal = GUICtrlCreateLabel("Ruta Final", 24, 96, 52, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###




While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $check1
            If IsChecked($check1) then
            GUICtrlSetState ($check2, $GUI_UNCHECKED)
            GUICtrlSetState ($check3, $GUI_UNCHECKED)
            EndIf

        Case $check2
            If IsChecked($check2) then
            GUICtrlSetState ($check1, $GUI_UNCHECKED)
            GUICtrlSetState ($check3, $GUI_UNCHECKED)
            EndIf

        Case $check3
            If IsChecked($check3) then
            GUICtrlSetState ($check2, $GUI_UNCHECKED)
            GUICtrlSetState ($check1, $GUI_UNCHECKED)
            EndIf

        Case $iniciar
            For $i = 0 to GUICtrlRead($texlimite, 1)
            If IsChecked($check1) then $input2 = StringFormat("%02s", $i)
            If IsChecked($check2) then $input2 = StringFormat("%03s", $i)
            If IsChecked($check3) then $input2 = StringFormat("%04s", $i)
            If IsChecked($check1) and IsChecked($check2) and IsChecked($check3) then $input2 =  $i
            $input = GUICtrlRead($texruta, 1)
                ;$input2 = $i
                ;$input2 = GUICtrlRead($i, 1)
                $input3 = GUICtrlRead($texrutafinal, 1)
                GUICtrlSetData($Edit1, $input & $input2 & $input3 & @CRLF, 1)
            Next

          Case $Limpiar
            GUICtrlSetData($Edit1, "")
   EndSwitch
WEnd


Func IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED)  
EndFunc   ;==>IsChecked

thanks
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...