Jump to content

"Loops"


Recommended Posts

Case $Button3
$Test=GUICtrlRead($Input1)
$Amount=GUICtrlRead($Input2)
$counter= 0
While $counter<=$Amount
MsgBox(0,"Value of $counter is:",$Test)
$counter = $counter +1
WEnd
For $counter = 1 to $Amount

Hello guys.

I want that the message box will show up that much times , as it has been declared in the $Input2. Actually its working like i put 5 in the $input2 and it shows up 6 time ( if i put 6 in input box , it shows up 7 times)

i already tried this :

$counter = $counter +0

but it didnt work.

Could anyone help me out with that ?

Link to comment
Share on other sites

  • Moderators

Hallistorm1989,

Remove the "=" from the condition - then you get the correct number of MsgBoxes: ;)

$Amount = 3

$counter = 0
While $counter < $Amount
    $counter = $counter + 1
    MsgBox(0, "Value of $counter is:", $counter)
WEnd

But it would be best to use a For...Next loop and let AutoIt count for you - like this: :)

For $i = 1 To $Amount
    MsgBox(0, "Value of $counter is:", $i)
Next

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Hallistorm1989,

The "3" was just for testing as I did not feel like creating a GUI to hold the input. It will still work with your code - but you might think of ensuring that you have a number in the input before you start looping. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Hallistorm1989,

The "3" was just for testing as I did not feel like creating a GUI to hold the input. It will still work with your code - but you might think of ensuring that you have a number in the input before you start looping. ;)

M23

Ok , last thing i have to fix is:

If i got for if i have -1 in $Input2

How Could i block -numbers for this input box ? :/

Edited by Hallistorm1989
Link to comment
Share on other sites

  • Moderators

Hallistorm1989,

Do as I suggested - get the content of the input and run some error-checking on it to make sure it is within bounds. Or you could force the input to accept only digits. Something like this should do the trick: ;)

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

GUICtrlCreateLabel("Only digits accepted!", 10, 10, 200, 20)
$cInput_1 = GUICtrlCreateInput("", 10, 30, 200, 20, $ES_NUMBER) ; Force digits only

$cInput_2 = GUICtrlCreateInput("", 10, 100, 200, 20)

$cButton = GUICtrlCreateButton("Read", 10, 200, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            $sContent_1 = GUICtrlRead($cInput_1)
            $sContent_2 = GUICtrlRead($cInput_2)
            ; Convert content of Input 2 to an integer
            $vContent_2 = Int(Number($sContent_2))
            ; Check this value to see if it is at least 1 or above
            If $vContent_2 < 1 Then
                $vContent_2 = "Error"
            EndIf

            MsgBox(0, "Result", "Input 1: " & $sContent_1 & @CRLF & "Input 2: " & $vContent_2)

            GUICtrlSetData($cInput_1, "")
            GUICtrlSetData($cInput_2, "")

    EndSwitch

WEnd

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Hallistorm1989,

Glad I could help. I see you got me to code a GUI in the end! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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