Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ARRAY 1

Status
Not open for further replies.

bebig

Technical User
Oct 21, 2004
111
US
I am trying ARRAY,
for example,
L1 --> 1 2 3
B1 --> 4 5 6
C1 --> 7 8 9
T1 --> 10 11 12

set listTable "$L1 $B1 $C1 $B2 $T1"

set indexLT1 [lindex $listTable 0]
set indexLT2 [lindex $listTable 1]
set indexLT3 [lindex $listTable 2]
set indexLT4 [lindex $listTable 3]
set indexLT5 [lindex $listTable 4]


how to use ARRAY...?
PLZ help me~~
thank you
 
L1 --> 1 2 3
B1 --> 4 5 6
C1 --> 7 8 9
T1 --> 10 11 12

set listTable "$L1 $B1 $C1 $B2 $T1"
puts $listTabel ---> 1 2 3 4 5 6 7 8 9 10 11 12
set indexLT1 [lindex $listTable 0]
set indexLT2 [lindex $listTable 1]
set indexLT3 [lindex $listTable 2]
set indexLT4 [lindex $listTable 3]
set indexLT5 [lindex $listTable 4]
----------------------------------------
but I want to have the results
1 2 3
4 5 6
7 8 9
10 11 12

how to use ARRAY...? or is there any way?
PLZ help me~~
thank you
 
bebig -

Your example (as presented) is not dealing with arrays.

You have to define your initial variables (i.e. - L1, B1, C1, & T1) as list, not as strings.

two ways of doing this:
> set L1 [list {1 2 3}] , or
> set L1 "{1 2 3}"

...then proceed as your doing.

FYI on arrays:
If you review your current store early/latest program you been using, I've resolved your problem by using arrays.

set StoreName ""
set StoreId ""
set StoreNum ""

for {set i 0} {$i < [llength $storeList]} {incr i} {

if {$StoreId == [lindex [lindex $storeList $i] 0]} {
lappend store($StoreId) [lindex $storeList $i]

} else {
set StoreId [lindex [lindex $storeList $i] 0]
lappend store($StoreId) [lindex $storeList $i]
}

if {[lsearch -exact $StoreName store($StoreId)] == -1} {
lappend StoreName store($StoreId)
lappend StoreNum $StoreId
}
}

set StoreNum [lsort -index 0 $StoreNum]
foreach elem $StoreNum {

set storeOpen($elem) [lsort -index 1 $store($elem)]
set storeClose($elem) [lsort -index 2 -decreasing $store($elem)]

puts "Store # $elem Early : [lindex [lindex $storeOpen($elem) 0] 1]"
puts "Store # $elem Lastest: [lindex [lindex $storeClose($elem) 0] 2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top