This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Transfer variable between proc's

Old posts that have not been replied to for several years.
Locked
Q
Quinie
Voice
Posts: 27
Joined: Fri Jan 09, 2004 5:29 am
Location: NL
Contact:

Transfer variable between proc's

Post by Quinie »

From 1 proc i call another proc that makes a sql querie.
I want to give the value of this querie back to the first prog. So the first proc can uses this value.

Can anyone tell me how to do this.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

one word one command

global varname

check out tcl manual on www.tcl.tk
XplaiN but think of me as stupid
Q
Quinie
Voice
Posts: 27
Joined: Fri Jan 09, 2004 5:29 am
Location: NL
Contact:

Post by Quinie »

This will change it into a global variable.
In that case it tought the value of the variable will not be emptyd as the proc ends.

But then again as i'm thinking i can drop it myself ofcource.

But can't this be done during the running of the procs only.
Like using the Return function or the upvar and getvar ?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Yes, upvar i think is what you are looking for.
The Manual wrote: upvar - Create link to variable in a different stack frame
or hmm.. uplevel - Execute a script in a different stack frame?
Once the game is over, the king and the pawn go back in the same box.
Q
Quinie
Voice
Posts: 27
Joined: Fri Jan 09, 2004 5:29 am
Location: NL
Contact:

Post by Quinie »

Could some-one post a example of upvar and/or uplevel.
Because i can't get it to work (i think it's me :) )
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

Code: Select all

# $Id: loader.tcl,v 0.2 2004/05/06 18:19:32 [Xp-AvR] Exp $

namespace eval ::loader {

  # Format:
  #   botnet-nick "tcls to load"
  array set Tcl2Load {
    ipv4 "scripts/tcl1.tcl scripts/tcl2.tcl"
    ipv6 "scripts/tcl2.tcl"
    bnc  "scripts/tcl3.tcl .data/.scripts/tcl55.tcl"
  } ;# Tcl2Load

  # LoadTcl
  proc LoadTcl { } {
    global botnet-nick
    variable Tcl2Load

    foreach tmpx [lsort [array names Tcl2Load]] {
      set botx [lindex $tmpx 0]
      if {${botnet-nick} == $botx} then {
        foreach tclx $Tcl2Load($botx) {
          uplevel #0 source $tclx
        }
        return 0
      }
    }
    return 0
  } ;# LoadTcl

  LoadTcl

} ;# namespace eval loader
:)
Que?
Q
Quinie
Voice
Posts: 27
Joined: Fri Jan 09, 2004 5:29 am
Location: NL
Contact:

Post by Quinie »

Well thanks it's nice to know some-one is trying to be helpfull. But it still doesn't give me any idea on how uplevel works. As I little by little understand more of TCL i still have a hard time figuring things out by meself.

It's just like the mann pages, if you are not native english or have studied it it's very hard to read. And i'm not natvie english or have studied it :)
From the man pages (www.hume.com/html84/mann/upvar.htm) i can understand you can only use uplevel is the first letter of your variable is a # or a digit.

But after that it's all some nice english [censored] for me. Are these mann pages also avalible in Dutch or could some-one explain it to me in more simple words. Because i would like to know what i'm doing. With two hours of coding i might get it to work but then i still don't know what i'm doing.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Translate to your native language then. :D
Once the game is over, the king and the pawn go back in the same box.
Q
Quinie
Voice
Posts: 27
Joined: Fri Jan 09, 2004 5:29 am
Location: NL
Contact:

Post by Quinie »

Well now it even harder to read.. :P :P

Well i think i'm just going to experiment. and lets see what happens.
I know now that i have to use upvar.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

You don't have to use upvar :wink:

Code: Select all

proc bla {bla bla bla} {
  #call proc 2 and catch the result 
  set result [bla2 bla]
}

proc bla2 {bla} {
  #do the sql querie and return the result
  return $result
}
... easy way to do it :wink:
Elen sila lúmenn' omentielvo
Q
Quinie
Voice
Posts: 27
Joined: Fri Jan 09, 2004 5:29 am
Location: NL
Contact:

Post by Quinie »

Thx.. working great...
you just made my day :D
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

just a little tip for those interested in upvar/uplevel..
http://dqd.com/~mayoff/notes/tcl/upvar.html
Elen sila lúmenn' omentielvo
Locked