2017-11-17 9:57 GMT+01:00 Dan Kennedy <danielk1...@gmail.com>:

>
> This gives:
>> wrong # args: should be "for start test next command"
>>      while executing
>> "for {t last_used loc} $teaChoices {
>>      puts $t
>> }
>>
>
> Sorry - [for] should be [foreach].
>
> So with your query as above, you want:
>
>   set teaChoices [db eval $getTeasToDrinkStr]
>   foreach t $teaChoices {
>     puts $t
>   }
>

​That solved it, yes.

​


>
> There is something going wrong, because:
>>      puts [llength teaChoices]
>> gives:
>>      1
>> while it should give:
>>      5​
>>
>
> Missing $ sign. Should be:
>
>   puts [llength $teaChoices]
>
> Without the $, it's returning the length of the literal "teaChoices" - one
> element. Not the length of the list contained in the variable named
> "teaChoices".


​That was the problem.


I am trying a bit different route:
    set teaList []
    db eval ${getTeasToDrinkStr} {
        lappend teaList [dict create                \
                             Tea        ${Tea}      \
                             LastUsed   ${LastUsed} \
                             Location   ${Location} \
                             Randomiser ${Randomiser}]
    }
    set i 0
    while {${i} < [llength ${teaList}]} {
        puts [format "%d: %-30s %-10s %2s %d" [expr ${i} + 1] \
                  [dict get [lindex $teaList ${i}] Tea]       \
                  [dict get [lindex $teaList ${i}] LastUsed]  \
                  [dict get [lindex $teaList ${i}] Location]  \
                  [dict get [lindex $teaList ${i}] Randomiser]]
        incr i
    }

This does what I want (I need the value of Tea to update the database), but
is there a better way?

-- 
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to