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

tcl if condition not working 1

Status
Not open for further replies.

sriks316

Programmer
Apr 15, 2012
1
US
What is wrong with my following code. It wont execute.

$pre_event_date =0;
set halBirthMovie "Jan 12, 1992"

if{$pre_event_date == 0} {
set halBirthMovie [clock format [clock scan $halBirthMovie] -format {%d %b}]
set pre_event_date [clock format [clock scan $pre_event_date] -format {%d %b}]
if{$pre_event_date != $halBirthMovie}{
puts "Not Equal"
}
else{
puts "Equal"
}

}
else{
puts "Nothing"
}
 
Wrong is how you format the if-else command.
See:

Your code will work if properly formatted:
Code:
[COLOR=#804040][b]set[/b][/color] pre_event_date [COLOR=#ff00ff]0[/color]
[COLOR=#804040][b]set[/b][/color] halBirthMovie [COLOR=#ff00ff]"Apr 16, 1992"[/color]

[COLOR=#804040][b]if[/b][/color] {[COLOR=#008080]$pre_event_date[/color] == [COLOR=#ff00ff]0[/color]} {
  [COLOR=#804040][b]set[/b][/color] halBirthMovie [[COLOR=#804040][b]clock[/b][/color] [COLOR=#804040][b]format[/b][/color] [[COLOR=#804040][b]clock[/b][/color] [COLOR=#804040][b]scan[/b][/color] [COLOR=#008080]$halBirthMovie[/color]] [COLOR=#ff0000]\[/color]
      -[COLOR=#804040][b]format[/b][/color] {%d %b}]
  [COLOR=#804040][b]set[/b][/color] pre_event_date [[COLOR=#804040][b]clock[/b][/color] [COLOR=#804040][b]format[/b][/color] [[COLOR=#804040][b]clock[/b][/color] [COLOR=#804040][b]scan[/b][/color] [COLOR=#008080]$pre_event_date[/color]] [COLOR=#ff0000]\[/color]
      -[COLOR=#804040][b]format[/b][/color] {%d %b}]
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"[/color][COLOR=#6a5acd]\$[/color][COLOR=#ff00ff]halBirthMovie  = [/color][COLOR=#008080]$halBirthMovie[/color][COLOR=#ff00ff]"[/color]
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"[/color][COLOR=#6a5acd]\$[/color][COLOR=#ff00ff]pre_event_date = [/color][COLOR=#008080]$pre_event_date[/color][COLOR=#ff00ff]"[/color]
  [COLOR=#804040][b]if[/b][/color] {[COLOR=#008080]$pre_event_date[/color] != [COLOR=#008080]$halBirthMovie[/color]} {
    [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Not Equal"[/color]
  } [COLOR=#804040][b]else[/b][/color] {
    [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Equal"[/color]
  }  
} [COLOR=#804040][b]else[/b][/color] {
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Nothing"[/color]
}
Output:
Code:
C:\_mikrom\Work>tclsh sriks316.tcl
$halBirthMovie  = 16 Apr
$pre_event_date = 16 Apr
Equal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top