Version 5 of Slot_Calculator_Demo

Updated 2009-01-16 15:00:51 by gold

       This page is under development. Comments are
       welcome, but please load any comments 
       at the bottom of the page. Thanks.

This page uses Tcl8/Expect 5.2 for windows to develop Slot_Calculator_Demo. (note: file is working in Expect5.2, but i did not put in statement "require Expect5.2" since lock with report error on some ports.)

In developing a computer program or application, it is helpful to develop analogs for the individual tasks of the application.

In the process of designing the basic subroutine tasks, we could throw in some error checks. Such rule breaking helps keep the finished program more flexible.


        #!/usr/bin/env wish
        #start of deck
        # Slot_Calculator_Demo
        # 5Feb2009, [gold]
frame .f1
frame .f2
frame .f3
frame .f4
frame .f5
set colorgrd seashell4
set colorback bisque
set colorwarning tomato1
set reportcard "ready"
set reportcard2 "zero entry detected !!! "
proc calculate { side1 side2  } {
    global colorwarning
    global colorback
    global answer2
  .f3.ee delete 0 end 
   .f5.ea delete 0 end
     .f5.ea configure -background $colorback 
     if {$side1 == ""} {
      set side1 .0000001
     .f5.ea delete 0 end
     .f5.ea configure -background $colorwarning
     .f5.ea insert end "warning, empty slot detected in entry"  
   }
   if {$side2 == ""} {
      set side2 .0000001
     .f5.ea delete 0 end
     .f5.ea configure -background $colorwarning
     .f5.ea insert end "warning, empty slot detected in entry"  
   }
   set answer2 [ expr { $side1 * $side2      }]
       .f3.ee insert end $answer2
     if {$answer2 <= 0.0000001} {
     .f5.ea delete 0 end
     .f5.ea configure -background $colorwarning 
     .f5.ea insert end "warning, negative or near zero detected in answer"  
   }
    if {$side1 <= 0.0000001} {
       .f5.ea delete 0 end
     .f5.ea configure -background $colorwarning
     .f5.ea insert end "warning, negative or near zero detected in entry"  
   } 
   if {$side2 <= 0.0000001} {
     .f5.ea delete 0 end
     .f5.ea configure -background $colorwarning 
     .f5.ea insert end "warning, negative or near zero detected in entry"  
   }
    
    if {$answer2 <= 0.0000001} {
     
     .f5.ea configure -background $colorwarning 
     .f5.ea insert end " !!! extra warning, negative or near zero detected in answer"  
   
}
}
proc testcasexxxx { side1 side2 answer } {
  # testcase is side of 5 units and 30 units
  # result or product is 150 units
  .f1.ee delete 0 end 
  .f2.ee delete 0 end 
  .f3.ee delete 0 end 
  .f5.ea delete 0 end
   .f1.ee insert end $side1
   .f2.ee insert end $side2
   .f3.ee insert end ""
   .f5.ea insert end "testcase entered, ans=150"
}
   proc clearall {  } {
    global colorwarning
    global colorback
     .f5.ea configure -background $colorback
  .f1.ee delete 0 end 
  .f2.ee delete 0 end 
  .f3.ee delete 0 end 
  .f5.ea delete 0 end
}
pack .f1 .f2 .f3 .f4 .f5 -side top -anchor w -fill x
label .f1.le -text "side 1" -background seashell1 -width 25 -anchor w
entry .f1.ee -textvariable side2  -background $colorback
pack .f1.le .f1.ee -side left
label .f2.le -text "side 2" -background seashell2  -width 25 -anchor w
entry .f2.ee -textvariable side1  -background $colorback
pack .f2.le .f2.ee -side left
label .f3.le -text "surface area " -background seashell3 -width 25 -anchor w
entry .f3.ee -textvariable xxxx  -background $colorback 
pack .f3.le .f3.ee -side left


button .f4.calculate -text calculate -background $colorgrd -command {calculate  $side1 $side2}

button .f4.testcase2 -text testcase -background $colorgrd -command {testcasexxxx  5  30 150 }
button .f4.clearxxxx -text "clear all"  -background $colorgrd -command {clearall}
button .f4.exitxxxx -text exit -background $colorgrd -command {exit}


pack .f4.calculate  .f4.testcase2 .f4.clearxxxx .f4.exitxxxx   -side left -expand 1

label .f5.la -text "report back " -background seashell2 -width 15 -anchor w
entry .f5.ea -textvariable "$reportcard" -width 50 -background $colorback 
pack .f5.la .f5.ea -side left
 .f5.ea insert end "ready"

canvas .c -width 40 -height 40 -relief sunken -bd 2
pack .c -side top -anchor w -fill both -expand yes


      #end of deck
      #end of deck      
      #end of deck
    #end of deck

Screenshots

http://img175.imageshack.us/img175/5109/ichinggenerator5ab5.jpg

Comments

Please place any comments here, Thanks.

gold Change:Redundant procedure ? deleted.


References

   *Programming References ( TCL & C# )***

Appendices

Tables