Prev: TclDevKit/Starpack failing to load a package DLL
Next: Problems reading from a specific web site
From: CWS on 5 Mar 2010 09:54 I have a tcl struct that i have created somewhere in my program like so: set array(0.x) 10 set array(0.y) 20 set array(0.z) 30 lets say i have 20 of these structs that have been filled with data. this array is not going to be global, no need for it. i just need to pass it to the appropriate functions when needed. I want to pass this to a proc and be able to retrieve the data(or print it out) but keep getting errors. i would also like to change values on the fly so that the original array also changes. I actually have this part working...so naturally i am confused as to why i cannot access the array when trying to output it to the screen. Can anyone help? Thanks much in advance. ***so if i have:*** proc print_array {arr} { upvar $arr a #set a(0.x) 25 <---update this value #puts "$a(0.x)" <---Error in startup script: can't read "a(0.x)": no such element in array while executing "puts "$a(0.x)"" } and in my main somewhere i have created and filled the array with values so i call the proc: print_array myArray puts "$myArray(0.x)" <---this prints out the changed value successfully from up in the proc.
From: Alexandre Ferrieux on 5 Mar 2010 10:50 On Mar 5, 3:54 pm, CWS <usmgoldenea...(a)gmail.com> wrote: > I have a tcl struct that i have created somewhere in my program like > so: > > set array(0.x) 10 > set array(0.y) 20 > set array(0.z) 30 > > lets say i have 20 of these structs that have been filled with data. > this array is not going to be global, no need for it. i just need to > pass it to the appropriate functions when needed. > > I want to pass this to a proc and be able to retrieve the data(or > print it out) but keep getting errors. i would also like to change > values on the fly so that the original array also changes. I actually > have this part working...so naturally i am confused as to why i cannot > access the array when trying to output it to the screen. > > Can anyone help? Thanks much in advance. > > ***so if i have:*** > > proc print_array {arr} { > > upvar $arr a > > #set a(0.x) 25 <---update this value > > #puts "$a(0.x)" <---Error in startup script: can't read "a(0.x)": no > such element in array while executing "puts "$a(0.x)"" > > } > > and in my main somewhere i have created and filled the array with > values so i call the proc: > > print_array myArray > > puts "$myArray(0.x)" <---this prints out the changed value > successfully from up in the proc. You're not showing the full initialization of your array, or with inconsistent names, and the comments in the proc make it hard to know what's enabled and what isn't. If you want to be helped efficiently, you need to be a bit more rigorous: just paste (don't type) the code of a script that has problems, and we'll help you bring it back to life. -Alex
From: CWS on 5 Mar 2010 11:54 On Mar 5, 9:50 am, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> wrote: > On Mar 5, 3:54 pm, CWS <usmgoldenea...(a)gmail.com> wrote: > > > > > I have a tcl struct that i have created somewhere in my program like > > so: > > > set array(0.x) 10 > > set array(0.y) 20 > > set array(0.z) 30 > > > lets say i have 20 of these structs that have been filled with data. > > this array is not going to be global, no need for it. i just need to > > pass it to the appropriate functions when needed. > > > I want to pass this to a proc and be able to retrieve the data(or > > print it out) but keep getting errors. i would also like to change > > values on the fly so that the original array also changes. I actually > > have this part working...so naturally i am confused as to why i cannot > > access the array when trying to output it to the screen. > > > Can anyone help? Thanks much in advance. > > > ***so if i have:*** > > > proc print_array {arr} { > > > upvar $arr a > > > #set a(0.x) 25 <---update this value > > > #puts "$a(0.x)" <---Error in startup script: can't read "a(0.x)": no > > such element in array while executing "puts "$a(0.x)"" > > > } > > > and in my main somewhere i have created and filled the array with > > values so i call the proc: > > > print_array myArray > > > puts "$myArray(0.x)" <---this prints out the changed value > > successfully from up in the proc. > > You're not showing the full initialization of your array, or with > inconsistent names, and the comments in the proc make it hard to know > what's enabled and what isn't. > > If you want to be helped efficiently, you need to be a bit more > rigorous: just paste (don't type) the code of a script that has > problems, and we'll help you bring it back to life. > > -Alex @Alex, thanks for the help. here is what i have... i am using wish and tcl version 8.3. i am fairly new to scripting and tcl so i am learning as i go. Anyway i am embarrassed to say that there was something going on in my loop that i messed up that i didnt show you in the first post. Anyway i solved that problem and now i can: proc update_data {name c} { upvar $name a puts "count is: $c" for { set i 0} {$i < $c} {incr i 1} { puts "$a($i.x) $a($i.y) $a($i.z)" } } everything works just fine. On another note, if i may, instead of making a whole new post, i would like to know how to place widgets, that is their x,y position on a canvas? I havent been able to find that anywhere that is clear in documentation or any examples. when i create a button widget for instance i want to be able to manually set an x,y pixel location of the button itself. This feature is not anywhere in the -option list that i have seen. I just want to be able to place widgets as i see fit without help from any frame or geometry manager. THANKS!!!! -Chad
From: Alexandre Ferrieux on 5 Mar 2010 12:01 On Mar 5, 5:54 pm, CWS <usmgoldenea...(a)gmail.com> wrote: > On Mar 5, 9:50 am, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> > wrote: > > > > > > > On Mar 5, 3:54 pm, CWS <usmgoldenea...(a)gmail.com> wrote: > > > > I have a tcl struct that i have created somewhere in my program like > > > so: > > > > set array(0.x) 10 > > > set array(0.y) 20 > > > set array(0.z) 30 > > > > lets say i have 20 of these structs that have been filled with data. > > > this array is not going to be global, no need for it. i just need to > > > pass it to the appropriate functions when needed. > > > > I want to pass this to a proc and be able to retrieve the data(or > > > print it out) but keep getting errors. i would also like to change > > > values on the fly so that the original array also changes. I actually > > > have this part working...so naturally i am confused as to why i cannot > > > access the array when trying to output it to the screen. > > > > Can anyone help? Thanks much in advance. > > > > ***so if i have:*** > > > > proc print_array {arr} { > > > > upvar $arr a > > > > #set a(0.x) 25 <---update this value > > > > #puts "$a(0.x)" <---Error in startup script: can't read "a(0.x)": no > > > such element in array while executing "puts "$a(0.x)"" > > > > } > > > > and in my main somewhere i have created and filled the array with > > > values so i call the proc: > > > > print_array myArray > > > > puts "$myArray(0.x)" <---this prints out the changed value > > > successfully from up in the proc. > > > You're not showing the full initialization of your array, or with > > inconsistent names, and the comments in the proc make it hard to know > > what's enabled and what isn't. > > > If you want to be helped efficiently, you need to be a bit more > > rigorous: just paste (don't type) the code of a script that has > > problems, and we'll help you bring it back to life. > > > -Alex > > @Alex, thanks for the help. here is what i have... > > i am using wish and tcl version 8.3. i am fairly new to scripting and > tcl so i am learning as i go. > > Anyway i am embarrassed to say that there was something going on in my > loop that i messed up that i didnt show you in the first post. Anyway > i solved that problem and now i can: > > proc update_data {name c} { > > upvar $name a > puts "count is: $c" > > for { set i 0} {$i < $c} {incr i 1} { > > puts "$a($i.x) $a($i.y) $a($i.z)" > } > > } > > everything works just fine. > > On another note, if i may, instead of making a whole new post, i would > like to know how to place widgets, Oh please do a new post, with a clear subject, otherwise it is really messy to follow, and even more to attract people with the answers. We'll immediately answer there. -Alex
From: Andreas Kupries on 6 Mar 2010 00:04 CWS <usmgoldeneagle(a)gmail.com> writes: > @Alex, thanks for the help. here is what i have... > > i am using wish and tcl version 8.3. i am fairly new to scripting and > tcl so i am learning as i go. http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html Note that this may contain 8.5 specific code in parts. The general stuff however is, well, general, and applies to 8.3 as well. ... 8.3 ... 8-10 years old now, depending on patch level (http://wiki.tcl.tk/405#pagetocf9d47aeb). -- So long, Andreas Kupries <akupries(a)shaw.ca> <http://www.purl.org/NET/akupries/> Developer @ <http://www.activestate.com/> -------------------------------------------------------------------------------
|
Next
|
Last
Pages: 1 2 Prev: TclDevKit/Starpack failing to load a package DLL Next: Problems reading from a specific web site |