INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Newbie and TCL script construct

Newbie and TCL script construct

(OP)

I am very new to TCL but am very familiar with shell scripting and currently looking at a system that is using TCL. I want to use functions/procedures in the TCL script but keep getting an error message that it cannot find "ssName". This is the very first function there will be more and am looking to "plug" in the new function code where I have marked it "Plugin here -->". Firstly the code below errors (why?) and secondly is my logic correct for adding new sections of code in the proc and thirdly....is there a better way of doing it.

Thanks in advance,

Madasafish

CODE -->

proc CheckPopUpMsg $ssName {
        if $ssName = "Pin_Protect_Res_704x480_51x655" {

        # If there is an image match to the pin protect screen
        # key in the pin
        if { [lindex $ret 0] == 0 } {

                # Press clear then key in pin
                ecp_stbcontrol any down;
                ecp_stbcontrol any left;
                ecp_stbcontrol any ok;
                ecp_stbcontrol any 1;
                ecp_stbcontrol any 2;
                ecp_stbcontrol any 3;
                ecp_stbcontrol any 4;
                ecp_stbcontrol any ok;
                }
        }
        Plugin here --> if $ssName = xyz 
}


# Main Prog
set channels [ecp_getchannels]
if {[llength $channels] == 0} {
        return -code error "No channels assigned. Cannot proceed."
}

foreach channel $channels {

        set ssName "Pin_Protect_Res_704x480_51x655"
        CheckPopUpMsg $ssName   #Call the function/procedure
        set ret [ecp_imagecompare 1.0 1.0 $ssName]
        ......
        ......etc, etc 

RE: Newbie and TCL script construct

Hi

  • Do not use sigil on formal parameters in the proc declaration.
  • Enclose if condition in braces ( {} ).
  • Use == for equality check.

CODE --> (briefly)

proc CheckPopUpMsg ssName {
        if {$ssName == "Pin_Protect_Res_704x480_51x655"} {

        }
} 

Feherke.
http://feherke.github.com/

RE: Newbie and TCL script construct

(OP)
Thank-you Ferherke

You corrections are have the program running - thank-you!

Would you be able to advise me on the correct TCL syntax to use given the above code to obtain the following equivalent in bash shell?

CODE -->

#!/bin/bash

proc()
{
case $1 in
        proc1)  echo "this is proc one"
                #more code here
                ;;
        proc2)  echo "this is proc two"
                #more code here
                ;;
        proc3)  echo "this is proc three"
                #more code here
                ;;
esac
}

for x in proc1 proc3 proc2
do
        proc $x
done

#Continue with more code here 

As always, thanks in advance

Madasafish

RE: Newbie and TCL script construct

Hi

Just to answer your question :

CODE --> Tcl

proc proc {something} \
{
  switch $something {
    proc1 {
      puts "this is proc one"
      # more code here
    }
    proc2 {
      puts "this is proc two"
      # more code here
    }
    proc3 {
      puts "this is proc three"
      # more code here
    }
  }
}

foreach x {proc1 proc3 proc2} {
  proc $x
} 
( Of course, calling the procedure proc is a bad idea. However it is allowed in Tcl. But be aware that the original proc command was overwritten and you can not define more procedures later. )

But I would try to solve it as possible without the switch. Ho idea how, hardly depends on what is your "more code here".

Feherke.
http://feherke.github.com/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close