• Passing parameters to procedure

    From snosniv@21:1/5 to All on Sat Feb 18 05:24:18 2023
    I generate a set of entry widgets & checkboxes as below:

    ##----------------------------------------------------------------------------- ## Labels & Entry for MultiBlock Rows 1 to 10 ##----------------------------------------------------------------------------- ## Grid placement for all the rows ##----------------------------------------------------------------------------- for {set xxx 0} {$xxx < 10} {incr xxx} {

    label $f4a.lb_TIM_$xxx -text "Time" -font {Arial 8 bold} -background white -foreground black
    label $f4a.lb_SPC_$xxx -text " " -font {Arial 8 bold}
    entry $f4a.enMINS_$xxx -textvar MB_mins_$xxx -width 2 -validate all -vcmd {ValidInt %P}
    entry $f4a.enSECS_$xxx -textvar MB_secs_$xxx -width 2 -validate all -vcmd {ValidInt %P}
    entry $f4a.enPWR_$xxx -textvar MB_power_$xxx -width 3 -validate all -vcmd {ValidInt %P}
    entry $f4a.enCAD_$xxx -textvar MB_cad_$xxx -width 3 -validate all -vcmd {ValidInt %P}
    checkbutton $f4a.cbSEL_$xxx -var MB_sel_$xxx -background white -foreground red


    grid $f4a.lb_TIM_$xxx -row [expr $xxx + 1] -column 0
    grid $f4a.enMINS_$xxx -row [expr $xxx + 1] -column 1
    grid $f4a.lb_SPC_$xxx -row [expr $xxx + 1] -column 2
    grid $f4a.enSECS_$xxx -row [expr $xxx + 1] -column 3
    grid $f4a.enPWR_$xxx -row [expr $xxx + 1] -column 4
    grid $f4a.enCAD_$xxx -row [expr $xxx + 1] -column 5
    grid $f4a.cbSEL_$xxx -row [expr $xxx + 1] -column 6
    }

    All that works fine, generating 10 rows each with 4 entries & a checkbox, so 50 data points.
    I cannot see to pass all that info to the procedure that works on the data except to pass all 50 individually, which is not great & pretty inelegant!

    Is there a nice clean way to pass the data to the proc?

    TIA, Kev P.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to snosniv on Sat Feb 18 14:46:56 2023
    At Sat, 18 Feb 2023 05:24:18 -0800 (PST) snosniv <[email protected]> wrote:


    I generate a set of entry widgets & checkboxes as below:

    ##-----------------------------------------------------------------------------
    ## Labels & Entry for MultiBlock Rows 1 to 10 ##-----------------------------------------------------------------------------
    ## Grid placement for all the rows ##-----------------------------------------------------------------------------
    for {set xxx 0} {$xxx < 10} {incr xxx} {

    label $f4a.lb_TIM_$xxx -text "Time" -font {Arial 8 bold} -background white -foreground black
    label $f4a.lb_SPC_$xxx -text " " -font {Arial 8 bold}
    entry $f4a.enMINS_$xxx -textvar MB_mins_$xxx -width 2 -validate all -vcmd {ValidInt %P}
    entry $f4a.enSECS_$xxx -textvar MB_secs_$xxx -width 2 -validate all -vcmd {ValidInt %P}
    entry $f4a.enPWR_$xxx -textvar MB_power_$xxx -width 3 -validate all -vcmd {ValidInt %P}
    entry $f4a.enCAD_$xxx -textvar MB_cad_$xxx -width 3 -validate all -vcmd {ValidInt %P}
    checkbutton $f4a.cbSEL_$xxx -var MB_sel_$xxx -background white -foreground red


    grid $f4a.lb_TIM_$xxx -row [expr $xxx + 1] -column 0
    grid $f4a.enMINS_$xxx -row [expr $xxx + 1] -column 1
    grid $f4a.lb_SPC_$xxx -row [expr $xxx + 1] -column 2
    grid $f4a.enSECS_$xxx -row [expr $xxx + 1] -column 3
    grid $f4a.enPWR_$xxx -row [expr $xxx + 1] -column 4
    grid $f4a.enCAD_$xxx -row [expr $xxx + 1] -column 5
    grid $f4a.cbSEL_$xxx -row [expr $xxx + 1] -column 6
    }

    All that works fine, generating 10 rows each with 4 entries & a checkbox, so 50 data points.
    I cannot see to pass all that info to the procedure that works on the data except to pass all 50 individually, which is not great & pretty inelegant!

    Is there a nice clean way to pass the data to the proc?

    All of the data is already in 50 global variables (that is what the -textvariable and -variable options do). You don't really need to "pass" anything at all -- the proc can just do something like:

    proc process {} {
    for {set xxx 0} {$xxx < 10} {incr xxx} {
    global MB_mins_$xxx MB_secs_$xxx MB_power_$xxx MB_cad_$xxx MB_sel_$xxx
    }

    # processing here, accessing MB_mins_0 ... MB_mins_9, MB_secs_0 ...
    # MB_secs_9, MB_power_0 ... MB_power_9, MB_cad_0 ... MB_cad_9, and MB_sel_0
    # ... MB_sel_9 as needed.
    }

    Note: rather then use 50 "uniquely" named globals, using a single global array might be better and easier to deal with (avoids having to deal with dereferencing generated variable names).

    entry $f4a.enMINS_$xxx -textvar data(MB_mins,$xxx) -width 2 -validate all -vcmd {ValidInt %P}
    entry $f4a.enSECS_$xxx -textvar data(MB_secs,$xxx) -width 2 -validate all -vcmd {ValidInt %P}
    entry $f4a.enPWR_$xxx -textvar data(MB_power,$xxx) -width 3 -validate all -vcmd {ValidInt %P}
    entry $f4a.enCAD_$xxx -textvar data(MB_cad,$xxx) -width 3 -validate all -vcmd {ValidInt %P}
    checkbutton $f4a.cbSEL_$xxx -var data(MB_sel,$xxx) -background white -foreground red


    Then your processing proc would look like:


    proc process {} {
    global data

    # Data accessed as:
    #
    # data(MB_mins,0), data(MB_mins,1), ... data(MB_mins,9)
    # data(MB_secs,0), data(MB_secs,1), ... data(MB_secs,9)
    # data(MB_power,0), data(MB_power,1), ... data(MB_power,9)
    # data(MB_cad,0), data(MB_cad,1), ... data(MB_cad,9)
    # data(MB_sel,0), data(MB_sel,1), ... data(MB_sel,9)

    }


    TIA, Kev P.



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    [email protected] -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to snosniv on Sat Feb 18 14:42:48 2023
    snosniv <[email protected]> wrote:
    All that works fine, generating 10 rows each with 4 entries & a
    checkbox, so 50 data points. I cannot see to pass all that info to
    the procedure that works on the data except to pass all 50
    individually, which is not great & pretty inelegant!

    Is there a nice clean way to pass the data to the proc?

    A list of 50 elements.

    A nested list of four columns, each containing ten rows.

    A Tcllib matrix of 10x4 (or 4x10) elements (man matrix).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)