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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

beginners guiding 1

Status
Not open for further replies.

kukelyk

Technical User
Mar 23, 2005
57
HU
hi
im new in tcl, im not a programmer, so i have many many problems...
my problem is finding the value of a numerical variable in a string.. how can i do this?
the string match command seems not to work..
thanks, kukelyk
 
You have to put that in. As it stands in my example, the file is only one line long.

_________________
Bob Rashkin
rrashkin@csc.com
 
i thought.. :)
i have problem with the combobox,
the wish prompt me: invalid command :-?
Code:
set post_fid [open H:\\CADCAM\\NX_Settings\\shop_doc\\tempvars\\posts r]
set postlistvar [split [gets $post_fid]]
close $post_fid
ComboBox -value $postlistvar
or whats wrong?
 
..i put the combobox.tcl to the auto_path..
 
You need to post more of what you're doing. But..
To instantiate the combobox, you need to have a package require Bwidgets statement at the start of your script. Then you need to define and pack (or place or grid) the combobox.

_________________
Bob Rashkin
rrashkin@csc.com
 
thanks..
i found the way in the meantime,
but.
(im not a programmer, but a lamer..)
i try to insert the elements of the
Code:
set postlistvar [split [gets $post_fid]]
$postlistvar list to the combobox,
but i can make only 2 items in the combobox:
the complete $postlistvar list, and an empty item.
if i select one, the list is cleared, so later, if i have more items, and fail the selection, there will be no other chance :(
 
That must be something in the parameters of the combobox. I did this test:

package require BWidget
pack [frame .1 -borderwidth 4] -side top
pack [ComboBox .1.cb]
set clist {abc def ghi jkl}
.1.cb configure -values $clist

Then the ComboBox menu had the 4 elements. Since the -values option takes the [red]$clist[/red] parameter rather than [red]clist[/red] as I had thought, you have to reconfigure after you add to the list:
lappend clist xyz
.1.cb configure -values $clist


_________________
Bob Rashkin
rrashkin@csc.com
 
Code:
set post_fid [open $shopdoc_temp_dir\posts r]
set postlist1 [split [gets $post_fid]]
set postlist2 [split [gets $post_fid]]
close $post_fid
::combobox::combobox $w.postcombo1\
	    -textvariable post \
	    -editable false\
	    -width 32
$w.postcombo1 configure -values $postlist1
grid $w.postcombo1 -row 1 -column 2

::combobox::combobox $w.postcombo2\
	    -textvariable post \
	    -editable false\
	    -width 32
$w.postcombo2 configure -values $postlist2
grid $w.postcombo2 -row 1 -column 3
i wrotethis script, but it does not works, it does not like the -values option..
if i comment the lines including "-values",
and change to it:
Code:
set post_fid [open $shopdoc_temp_dir\posts r]
set postlist1 [split [gets $post_fid]]
set postlist2 [split [gets $post_fid]]
close $post_fid
::combobox::combobox $w.postcombo1 -value 1\
	    -textvariable post \
	    -editable false\
	    -width 32
#$w.postcombo1 configure -values $postlist1
grid $w.postcombo1 -row 1 -column 2

::combobox::combobox $w.postcombo2\
	    -textvariable post \
	    -editable false\
	    -width 32
#$w.postcombo2 configure -values $postlist2
grid $w.postcombo2 -row 1 -column 3
then it works really strange. it looks, that the two combos link each other somehow..
 
Maybe because they use the same textvariable?

_________________
Bob Rashkin
rrashkin@csc.com
 
ah, i did not think...or did not understand what is the difference between the -value and the .textvariable

i dont know whats wrong.
if i use a list as the textvariable of the combo,
the list appears as a simple item in the list.
the script you wrote not works, but i dont know why..
Code:
set shopdoc_temp_dir "H:\\CADCAM\\NX_Settings\\shop_doc\\tempvars\\"
set post_fid [open $shopdoc_temp_dir\posts r]
set postlist1 [split [gets $post_fid]]
set postlist2  $postlist1
close $post_fid
set shopdoc_addon_dir "H:\\CADCAM\\NX_Settings\\shop_doc\\"
source $shopdoc_addon_dir\combobox.tcl
::combobox::combobox .postcombo1 -value {1 2}\
-textvariable post1 \
-editable false
grid .postcombo1 -row 1 -column 1
lappend  post1 {0 1 2 3 }
could you help me? thinking it is hard to me :-/
 
The [red]-values[/red] option specifies what values (strings) are listed in the ComboBox. The [red]-textvariable[/red] option specifies the name of variable that takes the value of the list item selected.

_________________
Bob Rashkin
rrashkin@csc.com
 
thank You Bong
you solved half my job...
but i have a problem again:
i want to get an item of a list, but i dont know which element, only with a variable:
Code:
set proc_run_num 2
set position $proc_run_num+2
#here is a problem, the $position will be 2+2 instead of 4
puts "lrange $list $position $position"
#will write: lrange <the content of the list> 2+2 2+2
whats wrong?
 
how can i empty a file?

or it is easier to recreate?
if i delete, how can i create it again?
 
In your code sample the statement set position $proc_run_num+2 will not perform the arithmetic indicated. You need to direct Tcl to evaluate an expression: set position [expr {$proc_run_num+2}].

Your other question how can i empty a file? isn't clear to me. If you want to take a file that has data in it and turn it into a file without data, but not delete it,
you can open it for writing and close it with no intervening action: set fid [open <file name> w]; close $fid.

What I think you really want to do is to have the same file name with some of the same contents (but not all) and some additional contents. If that is the case, how you do that depends somewhat on what the particulars are. One way is to read the file into memory (a list is my favorite), close the file, open it for writing (which effectively erases the contents), and then write the old data you want and the new data:
set fid [open <file name> r]
set linelist [split [read $fid] \n];[red]# each line is an element of the list[/red]
close $fid
[red]#identify which lines you want to write back out.
#lets say you want lines 0-3, 5, and 8[/red]
set fid [open <file name> w]
foreach lno {0 1 2 3 5 8} {puts $fid [lindex $linelist $lno]}
[red]#now add your new data[/red]
close $fid


Alternatively, you may want to keep only so many lines (say, 8) from the beginning of the file and then add new data. It might be simpler in that case to open a temporary file, copy the lines you want, add the new lines, close both files, delete the old file, and rename the temporary file:
set fid1 [open <old file name> r]
set fid2 [open <temp file name> w]
for {set i 0} {$i<8} {incr i} {puts $fid2 [gets $fid1]}
close $fid1
[red]#now add your new data[/red]
close $fid2
file delete <old file name>
file rename <temp file name> <old file name>


_________________
Bob Rashkin
rrashkin@csc.com
 
great.
but.
if a line contains whitespaces, when i write out the list item, it uses brackets, what looks awful in the output html file... how can i remove them?
Code:
...set data [read $fid]
close $fid
set lines [split $data \n]
set posts [lrange $lines 0 0]
puts $posts
or it is easier to replace whitespaces to "_"s before write it to the file, and after rereading data, redo it?
 
Try this:
change puts $posts
to puts [join $posts]

_________________
Bob Rashkin
rrashkin@csc.com
 
star.gif
star.gif
star.gif
star.gif
star.gif

thanx
 
hi again
how can i send " character to the output?
puts ""600"" ? it doesnt work..
it needed for html code:
puts "<H1 ALIGN=LEFT><img src='$imagename' width="900" height="600"></IMG></H1>"
or how can i bypass it?
thanx in advance
 
try puts \"600\"
the [red]\[/red] prevents the evaluation of "special" characters (making [red]\[/red], itself, a special character so to indicate it you use [red]\\[/red]).

_________________
Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top