Posted to tcl by mjanssen at Thu Feb 05 23:58:34 GMT 2009view raw

  1. # MJ abuse of globals
  2. # brace your expressions always even with catch !!!
  3.  
  4. proc {Get_Tube_Area_2} {} {
  5.  
  6. # MJ do these really have to be global
  7.  
  8. global tubeareafile
  9. global notubeareafile; set notubeareafile 0
  10.  
  11. global templateopt
  12.  
  13. # MJ ever heard of arrays?!?!
  14. global Area_tube_1
  15. global Area_tube_2
  16. global Area_tube_3
  17. global Area_tube_4
  18. global Area_tube_5
  19. global Area_tube_6
  20. global Area_tube_7
  21. global Area_tube_8
  22.  
  23. if [catch {open $tubeareafile r} fileId] {
  24. set message "Cannot open $tubeareafile\n"
  25. append message "Please search working directory\n"
  26.  
  27. # catch not needed
  28.  
  29. tk_messageBox -type ok -message $message -icon error
  30. puts "Cannot open $tubeareafile"
  31.  
  32. # MJ removed double open
  33.  
  34. # just return here and forget about the notblabla stuff!!
  35. set notubeareafile 1
  36. }
  37.  
  38. # MJ urgh are this coding conventions at work? Only one exit point in a proc
  39. if {$notubeareafile != 1} {
  40. # WTF, don't open it a third time!!! Three times' a charm?
  41. # catch {open $tubeareafile r} fileId
  42. while {[gets $fileId line] >= 0} {
  43. if {[string first "---TUBEAREA" $line] >= 0} {
  44.  
  45. # MJ urgh
  46. gets $fileId line
  47. gets $fileId line
  48. gets $fileId line
  49. gets $fileId line
  50. gets $fileId line
  51. gets $fileId line
  52. gets $fileId line
  53. gets $fileId line
  54. gets $fileId line
  55. gets $fileId line
  56. set line [string trim $line]
  57. set entry [parse $line]
  58. }
  59. }
  60.  
  61.  
  62. # probably a more general way!!
  63. if {"$templateopt" == "One Row"} {
  64. set Area_tube_1 [lindex $entry 1]
  65. set Area_tube_1 [format "%.2f" $Area_tube_1]
  66. }
  67. if {"$templateopt" == "Two Rows"} {
  68. set Area_tube_2 [lindex $entry 1]
  69. set Area_tube_2 [format "%.2f" $Area_tube_2]
  70. }
  71. close $fileId
  72.  
  73. # MJ no need to force, it wasn't fixing the bug
  74. file delete $tubeareafile
  75. }
  76. }