UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor tcl_balaji
Visitor
253 Views
Registered: ‎07-05-2019

How to get default value in swich

Hi,

I just reading and writing tcl about 10days,

I want to use a switch in Tcl

I use the below code, and I want to show default answer if no option selected:

#!/usr/bin/tclsh

#!/usr/bin/tclsh

puts "Main Menu"
puts "================"
puts "1. Show ip route"
puts "2. ping tftp server"
puts "3. list contents of disk0"

set menuitem 0

switch $menuitem {
1 {
puts "You selected menu item as $menuitem"
}
2 {
puts "You selected menu item as $menuitem"
}
3 {
puts "You selected menu item as $menuitem"
}
default {
"you have not selected"

}
}

when I set menuitem 1, 2, 3 it works correctly. But when I set menuitem 0, it did not work

0 Kudos
2 Replies
Xilinx Employee
Xilinx Employee
227 Views
Registered: ‎05-22-2018

Re: How to get default value in swich

Hi @tcl_balaji ,

What happens when you set menuitem default?

Thanks

Raj

0 Kudos
Visitor tcl_balaji
Visitor
195 Views
Registered: ‎07-05-2019

Re: How to get default value in swich

It give error as below:

$tclsh main.tcl
Main Menu ================ 1. Show ip route 2. ping tftp server 3. list contents of disk0 invalid command name "you have not selected" while executing ""you have not selected"" ("default" arm line 2) invoked from within "switch $menuitem { 1 { puts "You selected menu item as $menuitem" } 2 { puts "You selected menu item as $menuitem" } 3 { puts "You selec..." (file "main.tcl" line 13)
0 Kudos