Forum OpenACS Q&A: Re: How to get a value from a tcl file to other tcl file

It's not clear what you are trying to achieve.

1. One way is to store the value in a file (or back in the database) and then read it from y.tcl.

# 1.a (working with files) add this to the end of x.tcl file
set fp [open somefile.txt w]
puts $fp $count_num
close $fp

# 1.a (working with files) add this to the beginning of the y.tcl file
set fp [open somefile.txt]
set count_num [read $fp]
close $fp

# 1.b (working with db) add this to the end of x.tcl
# there are countless ways to do this, this is just a very basic example
# of what you can do. obviously, you would have to creat the table first:
# create table sometable (count_num integer);
db_dml delete_previous_count "delete from sometable"
db_dml save_count "insert into sometable (count_num) values (:count_num)"

# 1.b (working with db) add this to the beginning of y.tcl
set count_num [db_string get_count "select count_num from sometable"]

2. Another way is to source x.tcl in y.tcl but this would not work as you don't have the arguments of x.tcl in y.tcl. In any case, this is what you would need to do if you did have them:

# add this to the beginning of the y.tcl file
source x.tcl

3. Is this done in the context of a web app? Then, you have a form with those values and an action=y.tcl, which will then read the submitted query params with an ad_page_contract, i.e.:

# add this to the beginning of y.tcl
ad_page_contract {
@author yourname
} {
count_num:integer
}

PS. If you were to clarify what "getting count_num in y.tcl file" really means, it would be easier for us to answer.

Thanks  @Neophytos Demetriou

I am doing this for web app. I got solution for this, I did similar to your 3rd point.
I added the following code in my x.tcl which added count_num to "y.tcl url"

www.XXX/y?count_num=0

ad_returnredirect y?[ad_export_vars {count_num rel_type return_url}]

in y.tcl I added
ad_page_contract {
@author yourname
} {
count_num:optional
}

set count_num_p "f"
if {[exists_and_not_null count_num]} {
set count_num_p "t"
}

in y.adp

<if @count_num_p@ eq "t">
@count_num@
</if>