Version 3 of MetaKit Tips and Tricks

Updated 2007-05-27 09:24:26 by LES

A page for code snippets for MetaKit

CMcC found layout format annoying in its terseness, so wrote a simple wrapper to allow comments:

    proc layout {string} {
        set result ""
        foreach line [split $string \n] {
            set line [string trim [lindex [split $line \#] 0]]
            if {$line eq ""} continue
            foreach {name t} [split $line :] break
            if {$t eq ""} {
                set t "S"
            #puts stderr "Layout: $line -> $name:$t"
            append result "$name:$t" \n
        return $result


    set trouble_layout [layout {
        user        # user with trouble
        mid        # message id
        error:I        # error code
        text        # error text

    ::mk::view layout $db.trouble $trouble_layout

How do I get a 'distinct' item result set?

Partnumber 0001 0001 0001 0003 0004 0006 0006

and you want to retrieve the unique values only -- such as:

Partnumber 0001 0002 0003 0004 0006

 # code here

LES answers: see lsort -unique: [L1 ]

LES on 20070527: Suppose you have these values: John 48 male. You can't enter them like this. The correct way is name John age 48 sex male. That requirement is annoying, especially when importing from CSV. So I made this proc:

 proc  mk.row.importvalues  {View Properties Values}          {

         if          {[llength $Properties] != [llength $Values]}  {
                 puts {Error: "Properties" and "Values" must be lists and have the same number of elements.}

         for          {set i 0}  {$i < [llength $Values]}  {incr i}  {
                 lappend ImportValues [lindex $Properties $i]
                 lappend ImportValues [lindex $Values $i]

         mk::row append $View $ImportValues


 mk.row.importvalues $view "name age sex" "John 48 male"


 foreach line $all_lines_of_a_file {
         mk.importvalues $view "name age sex" $line

Remove the commas from every line if it is a CSV:

 foreach line $all_lines_of_a_file {
         mk.importvalues $view "name age sex" [string map {, ""} $line]