Jump to content

I need general help


Recommended Posts

I need to create a function that do infinite loop and the output is 4,5,4,5,4,5

What function to replace the ? Sign in order to accomplish it?

Func ()

$x=4

While(true)

$x=?

Debugoutput(x & ',')

Wend

Endfunc

Example:

If x=4 then the output should be;

4,5,4,5,4,5,

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

  • Moderators

lsakizada,

I would do it using Mod like this: :)

HotKeySet("{ESC}", "On_Exit")

$i = 1

While 1
    ; Toggle $i between 0 and 1
    $i = Mod($i + 1, 2)
    ; Add 4
    ConsoleWrite(4 + $i & @CRLF)
    ; Just to see the result
    Sleep(250)
WEnd

Func On_Exit()
    Exit
EndFunc
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

Hi melba32, nice to get response from you ;)

Thanks for correcting the syntax, i am on iphone.

It is almost ok, i must need to replace the '?' Sign with a proper function in order to print the desired output. Btw, it is a question that i have being asked today in my job interview.

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

  • Moderators

lsakizada,

Then perhaps this:

HotKeySet("{ESC}", "On_Exit")

$i = 4

While 1
    ; Toggle $i between 4 and 5
    $i = 4 + Mod(($i - 4) + 1, 2)
    ConsoleWrite($i & ",")
    ; Just to see the result
    Sleep(250)
WEnd

Func On_Exit()
    Exit
EndFunc
Good luck with the interview. ;)

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

Hi melba, this solution works but not for ANY $i variable, Which mean the digit 4 should not be used in the function.

Yep, I am still need to supply the complete solution in order to put bread on my table.

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Isakizada,

Maybe somethiing as simple as this

HotKeySet("{ESC}", "On_Exit")

$i = 6

While 1
    ConsoleWrite($i & ',' & $i+1 & ',')
    Sleep(250)
WEnd

Func On_Exit()
    ConsoleWrite(@LF)
    Exit
EndFunc

Good Luck with the $$$$$

 

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

  • Moderators

lsakizada,

How about you tell me ALL the constraints on the solution before I produce any more new code - I really dislike having the goalposts moved after every solution I post. ;)

For example, are we limited to just one line or can I call a function? :huh:

M23

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

Melba,

Well, as I just told to kylomas, the interviewer asked to replace only the '?' Sign with proper function. Beside of that, that's should works for any number that assigned to the first variable before entering the infinity loop. Yours solution is Ok, but I am not sure if it will works if we will replace the digit 4 with the variable $i. I can not test it since i am on my iphone.

Thanks for the help!

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

  • Moderators

lsakizada,

If we can use a function the solution is very simple:

HotKeySet("{ESC}", "On_Exit")

$i = 4

While 1
    ; Toggle $i between 4 and 5
    $i = _Func($i)
    ConsoleWrite($i & ",")
    ; Just to see the result
    Sleep(250)
WEnd

Func _Func($iVar)
    ; Set a static variable to store the first value of the variable received by the function
    Static $iBase = 0
    If $iBase = 0 Then $iBase = $iVar
    ; And run the one-liner we had before
    Return $iBase + Mod(($iVar - $iBase) + 1, 2)
EndFunc

Func On_Exit()
    Exit
EndFunc
How about that? :)

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

danwilli,

:thumbsup:

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