Jump to content

Logic Question


Iceburg
 Share

Recommended Posts

Iceburg,

This may be of some use. See the comments in the code.

Global $aFuncs[5] =["Func_1", "Func_2", "Func_3", "Func_4", "Func_5"]
While 1
    $iStart = Random(0, 4, 1)   ; <<<<<<<<<<  changed so that you only have to change the $afuncs array to add/sub functions
    For $i = 0 To ubound($aFuncs) - 1
        $iIndex = Mod($i + $iStart, 5)
        Call($aFuncs[$iIndex], random(0,99,1), random(0,99,1))  ; mult args, can be as many as defined on the func stmt
    Next
    ConsoleWrite(@CRLF)
    If MsgBox(4, "Finished", "Ready for another run?") = 7 Then
        ExitLoop
    EndIf
WEnd
Func Func_1($var, $var2 = '', $var3 = '')    ; using this syntax makes the vars optional on the call stmt
    ConsoleWrite("Func 1 called " & stringformat('%-5s%-5s%-5s',$var,$var2,$var3) & @CRLF)
EndFunc
Func Func_2($var, $var2 = '', $var3 = '')
    ConsoleWrite("Func 2 called " &  stringformat('%-5s%-5s%-5s',$var,$var2,$var3) & @CRLF)
EndFunc
Func Func_3($var, $var2 = '', $var3 = '')
    ConsoleWrite("Func 3 called " &  stringformat('%-5s%-5s%-5s',$var,$var2,$var3) & @CRLF)
EndFunc
Func Func_4($var, $var2 = '', $var3 = '')
    ConsoleWrite("Func 4 called " &  stringformat('%-5s%-5s%-5s',$var,$var2,$var3) & @CRLF)
EndFunc
Func Func_5($var, $var2 = '', $var3 = '')
    ConsoleWrite("Func 5 called " &  stringformat('%-5s%-5s%-5s',$var,$var2,$var3) & @CRLF)
EndFunc

kylomas

edit: the first comment should be on the next line down

Edited by 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

Iceburg,

The above will work, however, if I was going to handle a variable number of parms I would pass an array like the following.

Global $aFuncs[5] =["Func_1", "Func_2", "Func_3", "Func_4", "Func_5"]

local $aMyparms[20]

While 1
    $iStart = Random(0, 4, 1)
    For $i = 0 To ubound($aFuncs) - 1
        $iIndex = Mod($i + $iStart, 5)

        for $j = 0 to ubound($aMyparms) - 1
            $aMyparms[$j] = random(0,99,1)
        next

        Call($aFuncs[$iIndex], $aMyparms)
    Next
    ConsoleWrite(@CRLF)
    If MsgBox(4, "Finished", "Ready for another run?") = 7 Then
        ExitLoop
    EndIf
WEnd
Func Func_1($aVars)
    local $str
    for $i = 0 to ubound($aVars) - 1
        $str &= stringformat('%-5s',$aVars[$i])
    next
    ConsoleWrite("Func 1 called " & $str & @lf)
EndFunc
Func Func_2($aVars)
    local $str
    for $i = 0 to ubound($aVars) - 1
        $str &= stringformat('%-5s',$aVars[$i])
    next
    ConsoleWrite("Func 2 called " & $str & @lf)
EndFunc
Func Func_3($aVars)
    local $str
    for $i = 0 to ubound($aVars) - 1
        $str &= stringformat('%-5s',$aVars[$i])
    next
    ConsoleWrite("Func 3 called " & $str & @lf)
EndFunc
Func Func_4($aVars)
    local $str
    for $i = 0 to ubound($aVars) - 1
        $str &= stringformat('%-5s',$aVars[$i])
    next
    ConsoleWrite("Func 4 called " & $str & @lf)
EndFunc

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

Iceberg,

Or this wayto generate a random number of parms

Global $aFuncs[5] =["Func_1", "Func_2", "Func_3", "Func_4", "Func_5"]

While 1
    $iStart = Random(0, 4, 1)
    For $i = 0 To ubound($aFuncs) - 1
        $iIndex = Mod($i + $iStart, 5)

        local $aMyparms[20]
        for $j = 0 to random(0,ubound($aMyparms) - 1,1)
            $aMyparms[$j] = random(0,99,1)
        next

        Call($aFuncs[$iIndex], $aMyparms)
        $aMyparms = 0

    Next
    ConsoleWrite(@CRLF)
    If MsgBox(4, "Finished", "Ready for another run?") = 7 Then
        ExitLoop
    EndIf
WEnd
Func Func_1($aVars)
    local $str
    for $i = 0 to ubound($aVars) - 1
        $str &= stringformat('%-5s',$aVars[$i])
    next
    ConsoleWrite("Func 1 called " & $str & @lf)
EndFunc
Func Func_2($aVars)
    local $str
    for $i = 0 to ubound($aVars) - 1
        $str &= stringformat('%-5s',$aVars[$i])
    next
    ConsoleWrite("Func 2 called " & $str & @lf)
EndFunc
Func Func_3($aVars)
    local $str
    for $i = 0 to ubound($aVars) - 1
        $str &= stringformat('%-5s',$aVars[$i])
    next
    ConsoleWrite("Func 3 called " & $str & @lf)
EndFunc
Func Func_4($aVars)
    local $str
    for $i = 0 to ubound($aVars) - 1
        $str &= stringformat('%-5s',$aVars[$i])
    next
    ConsoleWrite("Func 4 called " & $str & @lf)
EndFunc

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

I only have one function, so I am setting up all my args:

Its not liking: $args[$iIndex][0]

global $incoming_var, $spot
global $A_args0[7]=["1", "1", "11", $incoming_var, $spot, "1", "5"]
global $A_args1[7]=["1", "1", "11", $incoming_var, $spot, "1", "6"]
global $A_args2[7]=["1", "1", "11", $incoming_var, $spot, "1", "7"]
global $A_args3[7]=["1", "2", "10", $incoming_var, $spot, "1", "5"]
global $A_args4[7]=["1", "2", "10", $incoming_var, $spot, "1", "6"]
global $A_args5[7]=["1", "2", "10", $incoming_var, $spot, "1", "7"]
global $A_args6[7]=["2", "1", "11", $incoming_var, $spot, "1", "5"]
global $A_args7[7]=["2", "1", "11", $incoming_var, $spot, "1", "6"]
global $A_args8[7]=["2", "1", "12", $incoming_var, $spot, "1", "7"]
global $A_args9[7]=["2", "2", "11", $incoming_var, $spot, "1", "5"]
global $A_args10[7]=["2", "2", "11", $incoming_var, $spot, "1", "6"]
global $A_args11[7]=["2", "2", "11", $incoming_var, $spot, "1", "7"]



$iStart = Random(0, 11, 1)
For $i = 0 To 11
$iIndex = Mod($i + $iStart, 11)
Call ("tracker", $args[$iIndex][0], $A_args[$iIndex][1], $A_args[$iIndex][2], $A_args[$iIndex][3], $A_args[$iIndex][4], $A_args[$iIndex][5], $A_args[$iIndex][6])
Next


Func tracker($flight, $a_or_b, $page_number, $URL, $URL_page, $customer_type, $spare)
ConsoleWrite($flight, $a_or_b, $page_number, $URL, $URL_page, $customer_type, $spare)
EndFunc

Edit: added declarations for ease of copy and pasting for testing.

Edited by Iceburg
Link to comment
Share on other sites

Iceberg,

Because you are referencing a one dimensional array as a two dimensional array. If you are going to one function you do not need all the logic for running multiple funcs. Change the definition of your arrays. You are declaring them as a 1D array and initializing them as a 2D array.

I suggest you use one array as follows

local $a_args[11][7]

This creates one array of 11 lines, each line comprised of 7 columns.

kylomas

edit: my f$%^$#king keyboard is broke

Edited by 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

Iceberg,

Try this

global $incoming_var, $spot
global $A_args[12][7]=[ _
    ["1", "1", "11", $incoming_var, $spot, "1", "5"], _
    ["1", "1", "11", $incoming_var, $spot, "1", "6"], _
    ["1", "1", "11", $incoming_var, $spot, "1", "7"], _
    ["1", "2", "10", $incoming_var, $spot, "1", "5"], _
    ["1", "2", "10", $incoming_var, $spot, "1", "6"], _
    ["1", "2", "10", $incoming_var, $spot, "1", "7"], _
    ["2", "1", "11", $incoming_var, $spot, "1", "5"], _
    ["2", "1", "11", $incoming_var, $spot, "1", "6"], _
    ["2", "1", "12", $incoming_var, $spot, "1", "7"], _
    ["2", "2", "11", $incoming_var, $spot, "1", "5"], _
    ["2", "2", "11", $incoming_var, $spot, "1", "6"], _
    ["2", "2", "11", $incoming_var, $spot, "1", "7"] _
    ]

$iStart = Random(0, 11, 1)
For $i = 0 To 11
    $iIndex = Mod($i + $iStart, 11)
    Call ("tracker", $A_args[$iIndex][0], $A_args[$iIndex][1], $A_args[$iIndex][2], $A_args[$iIndex][3], $A_args[$iIndex][4], $A_args[$iIndex][5], $A_args[$iIndex][6])
Next


Func tracker($flight, $a_or_b, $page_number, $URL, $URL_page, $customer_type, $spare)
ConsoleWrite($flight & ' ' & $a_or_b & ' ' & $page_number & ' ' & $URL & ' ' & $URL_page & ' ' & $customer_type & ' ' & $spare)
EndFunc

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

Lol beat me to it. Here goes anyway:

Global $incoming_var = "?", $spot = "?"

Global $a_Args[12][7] = _
[["1", "1", "11", $incoming_var, $spot, "1", "5"], _
["1", "1", "11", $incoming_var, $spot, "1", "6"], _
["1", "1", "11", $incoming_var, $spot, "1", "7"], _
["1", "2", "10", $incoming_var, $spot, "1", "5"], _
["1", "2", "10", $incoming_var, $spot, "1", "6"], _
["1", "2", "10", $incoming_var, $spot, "1", "7"], _
["2", "1", "11", $incoming_var, $spot, "1", "5"], _
["2", "1", "11", $incoming_var, $spot, "1", "6"], _
["2", "1", "12", $incoming_var, $spot, "1", "7"], _
["2", "2", "11", $incoming_var, $spot, "1", "5"], _
["2", "2", "11", $incoming_var, $spot, "1", "6"], _
["2", "2", "11", $incoming_var, $spot, "1", "7"]]



$iStart = Random(0, 11, 1)
For $i = 0 To 11
    $idx = Mod($i + $iStart, 11)
    tracker($a_Args[$idx][0], $a_Args[$idx][1], $a_Args[$idx][2], $a_Args[$idx][3], $a_Args[$idx][4], $a_Args[$idx][5], $a_Args[$idx][6])
Next


Func tracker($flight, $a_or_b, $page_number, $URL, $URL_page, $customer_type, $spare)
    ConsoleWrite($flight & " " & $a_or_b & " " & $page_number & " " & $URL & " " & $URL_page & " " & $customer_type & " " & $spare & " " & @CRLF)
EndFunc

Why is my code wrapping?

Edit

Hopefully this edit will fix it. Nope it's not fixed it. You will have to click the Popup button to get the correct code. I am having issues posting in the code boxes. Actually I think it's IE on my computer.

Edited by czardas
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...