Jump to content

represent infinite $variable?


HankHell
 Share

Recommended Posts

hey guys, I was trying to figure out how to make an infinite variable, as in the case below

Global $count = 0
Global $userinput = 5


HotKeySet("{F1}", "Cycle")
HotKeySet("{ESC}", "End")

Sleeptime()

Func Sleeptime()
    While 1
        Sleep(100)
    WEnd
EndFunc

Func Cycle()
    While 1

        If $userinput = 0 Then
            $userinput = $userinput + 1
        Else
        If $count = $userinput Then
            $count = 0
            ExitLoop
        EndIf
        EndIf
            $count = $count + 1
;add junk here

        ;Example
        Send($count)
        ;Example

    WEnd
EndFunc

Func End()
    Exit
EndFunc

basically, I want to replace this:

If $userinput = 0 Then
            $userinput = $userinput + 1

with something like this:

If $userinput = 0 Then
            $userinput = ;infinity?

 

Link to comment
Share on other sites

  • Moderators

HankHell,

A simple check should do the trick:

Global $count = 0
Global $userinput = 0

HotKeySet("{F1}", "Cycle")
HotKeySet("{ESC}", "End")

Sleeptime()

Func Sleeptime()
    While 1
        Sleep(10) ; 10 is enough Sleep
    WEnd
EndFunc   ;==>Sleeptime

Func Cycle()
    While 1
        ; Check for infinite looping
        If $userinput <> 0 Then
            ; Check for loop limit
            If $count = $userinput Then
                $count = 0
                ExitLoop
            EndIf
        EndIf
        $count = $count + 1
        ;add junk here

        ;Example
        ConsoleWrite($count & @CRLF)
        ;Send($count)
        ;Example

        Sleep(10) ; Do not CPU here either!

    WEnd
EndFunc   ;==>Cycle

Func End()
    Exit
EndFunc   ;==>End

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

HankHell,

Neither could you in the original script - I assumed that was just an example of the loop.

Just add another function for the user input:

Global $count = 0
Global $userinput = 5

HotKeySet("{F1}", "Cycle")
HotKeySet("{F2}", "Input")
HotKeySet("{ESC}", "End")

Sleeptime()

Func Sleeptime()
    While 1
        Sleep(10) ; 10 is enough Sleep
    WEnd
EndFunc   ;==>Sleeptime

Func Input()
    $userinput = Number(InputBox("Loops", "How many? (0=infinite)"))
EndFunc

Func Cycle()
    While 1
        ; Check for infinite looping
        If $userinput <> 0 Then
            ; Check for loop limit
            If $count = $userinput Then
                $count = 0
                ExitLoop
            EndIf
        EndIf
        $count = $count + 1
        ;add junk here

        ;Example
        ConsoleWrite($count & @CRLF)
        ;Send($count)
        ;Example

        Sleep(10) ; Do not CPU here either!

    WEnd
EndFunc   ;==>Cycle

Func End()
    Exit
EndFunc   ;==>End

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

5 minutes ago, Melba23 said:

HankHell,

Neither could you in the original script - I assumed that was just an example of the loop.

Just add another function for the user input:

Global $count = 0
Global $userinput = 5

HotKeySet("{F1}", "Cycle")
HotKeySet("{F2}", "Input")
HotKeySet("{ESC}", "End")

Sleeptime()

Func Sleeptime()
    While 1
        Sleep(10) ; 10 is enough Sleep
    WEnd
EndFunc   ;==>Sleeptime

Func Input()
    $userinput = Number(InputBox("Loops", "How many? (0=infinite)"))
EndFunc

Func Cycle()
    While 1
        ; Check for infinite looping
        If $userinput <> 0 Then
            ; Check for loop limit
            If $count = $userinput Then
                $count = 0
                ExitLoop
            EndIf
        EndIf
        $count = $count + 1
        ;add junk here

        ;Example
        ConsoleWrite($count & @CRLF)
        ;Send($count)
        ;Example

        Sleep(10) ; Do not CPU here either!

    WEnd
EndFunc   ;==>Cycle

Func End()
    Exit
EndFunc   ;==>End

M23

ah yeah didn't think of that, thanks

 

also, yes this was just a representation and not the script I'm working on

Edited by HankHell
Link to comment
Share on other sites

  • Moderators

HankHell,

Thinking a little deeper, best change the comparison to:

; Check for loop limit
If $count >= $userinput Then

Now if the user enters a valid number while the loop is infinite it will stop if already over the limit. Or reset $count to 0 at the same time as getting the new input.

M23

P.S. When you reply in future, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily. Thanks in advance for your cooperation.

 

Edited by Melba23

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

Just now, Melba23 said:

HankHell,

Thinking a little deeper, best change the comparison to:

; Check for loop limit
If $count >= $userinput Then

Now if the user enters a valid number while the loop is infinite it will stop if already over the limit. Or reset $count to 0 at the same time as getting the new input.

M23

ah yeah, good idea, I was thinking something similar as well. thanks a bunch for the help :P

Link to comment
Share on other sites

  • Moderators

HankHell,

My pleasure as always.

But please read the P.S. on the above post.

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