views:

27

answers:

1

Hello:

In short, currently I am using the following code to pull records from multiple tables in a Sqlite Db and insert them in a single combobox ($SearchBar):

set SrchVals1 [db eval {SELECT DISTINCT Stitle From Subcontract Order By Stitle ASC}]
set SrchVals2 [db eval {...
set SrchVals3 ...
set SrchValsALL [concat $SrchVals1 $SrchVals2 $SrchVals3]
$SearchBar configure -value $SrchValsAll

For the variable "SrchVals1", I am trying to figure out a way to concatenate the text "Sub: " to each individual record in SrchVals1. For example, if SrchVals1 shows the following records in the combobox:

First Title
Second Title
Third Title

I would like to concatenate so that the records in the combobox look like this:

Sub: First Title
Sub: Second Title
Sub: Third Title

I understand that I might have to use a foreach statement; however, I am having no luck writing one that adds "Sub: " in front of each record, as opposed to one. This seems like something that should be pretty easy, but I cannot seem to figure it out.

Does anyone know how I can achieve these results?

Thank you,

DFM

+2  A: 

You're right. The foreach command is the right way to do it. Here's how:

set SrchValsALL {}
foreach value [concat $SrchVals1 $SrchVals2 $SrchVals3] {
    lappend SrchValsALL "Sub: $value"
}
$SearchBar configure -value $SrchValsAll
Donal Fellows