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

undefined behaviour? 1

Status
Not open for further replies.

reggler

Programmer
Nov 13, 2008
63
CA
Hi There,

I have a certain proc from where i want to open a dialog box requiring a user to choose an option. Once the user has hit the button, i set a variable and my initial proc should continue where it has left off (opened the window).
I tried this with this code:

show window and wait for action:
Code:
set finaltest::Order_Select_done 0
wm deiconify .winOrder
vwait finaltest::Order_Select_done
wm withdraw .winOrder

And below proc gets triggered when the OK button on the window is hit:
Code:
proc finaltest::Order_Indicate {} {
    if {($finaltest::Order_value == 1) || ($finaltest::Order_value == -1)} {
	    #GUI::Info_DialogWIN "finaltest::Order_value: $finaltest::Order_value"
        set finaltest::Order_Select_done $finaltest::Order_value
        set finaltest::Order_value 0
        return 0
    } else  {
	    GUI::Error_DialogWIN "FatalError:\n finaltest::Order_value: $finaltest::Order_value"
        return 1
    }
}
And now what's happening (only on certain machines apparently) is that the application just hangs and windows says "not responding" - how come? Is this an undefined condition or something? What's going wrong here? I just realized that this is happening today for the first time just on my machine apparently - and yes, i have rebooted! :eek:

Thanks!

Ron
Hours of planing can save weeks of coding
 
Do you have a namespace defined for finaltest? Anyway, it sounds to me like a scope problem. Try putting the test variable in the global scope in both cases (that is, in the proc, too). The hanging could just be that it's waiting for the wrong variable.

_________________
Bob Rashkin
 
it still does not wanna work :(
What I got now:
proc that gets triggered by the OK button on the dialog window button .winOrder.ok -command {finaltest::Order_Indicate} \
-text OK -font 10 -pady 0 -state normal -width 10

Code:
proc finaltest::Order_Indicate {} {
	global Order_Select_done
    if {($finaltest::Order_value == 1) || ($finaltest::Order_value == -1)} {
	    #GUI::Info_DialogWIN "finaltest::Order_value: $finaltest::Order_value"	   
        set Order_Select_done $finaltest::Order_value
        set finaltest::Order_value 0
        return 0
    } else  {
	    GUI::Error_DialogWIN "FatalError:\n finaltest::Order_value: $finaltest::Order_value"
        return 1
    }
}
snippet that's waiting for Order_Select_done to change:
Code:
    if {$finaltest::select_pretest_finaltest_boards == 0} {;#Pre-test
        if {$finaltest::firmwareoption == 1} {
            if {![string match RX* $finaltest::product(family)]} {
	            GUI::Info_DialogWIN "just before firmware selection window\nfinaltest::product(family): $finaltest::product(family)"
                set finaltest::Order_Select_done 0
                global Order_Select_done
                set Order_Select_done 0                
                wm deiconify .winOrder
                vwait Order_Select_done
                wm withdraw .winOrder
            }
        }
    }
But still, my dialog stays open when i hit the OK button, it doesn't get withdrawn.... :(

Ron
Hours of planing can save weeks of coding
 
I guess I don't know what your process looks like. The dialog is "modal" meaning (among other things I'm not sure of) that the process is halted until the dialog is executed. After that, what are you waiting for?

_________________
Bob Rashkin
 
Yup, it actually is hung in my retrieve function (where i open a file... i wasn't aware of the fact that this could be the problem... :eek:
I would like to open a file of ~20MB that is saved on a network share (samba, LAN). My proc looks like this:
Code:
proc finaltest::retrieve {target perm startTime} {
    #puts "begin to run finaltest::retrieve($target $perm $startTime)"
    while {[expr $startTime+$finaltest::const(FILE_TIMEOUT)]>[clock seconds]} {
        if ![catch {open $target $perm} fileId] {return $fileId}
        after 2000
    }
    GUI::displayError 3
    #puts "finished finaltest::retrieve($target $perm $startTime)"
    return TIMEOUT
}

Does any one have an idea what makes it being hung? I just open it and return the handle - so what could be the problem?
Thank you!
Ron

Ron
Hours of planing can save weeks of coding
 
Oh no wrong, sorry...the file handle gets opened appropriately but i need to read the last line of the file only. How can I start reading from the bottom or set the file pointer to its handle's end?

The current code look like this:
Code:
    while {[eof $fileId]!=1} {
        gets $fileId newline
        if {[string length $newline]>=10} {
            set lastline $newline
        }
    }
I hope there's a better way than above snippet that would achieve the same.

Thanks,
Ron

Ron
Hours of planing can save weeks of coding
 
Well, that's a whole different question. You can use seek to position the next file read:
Code:
seek $fileId $n end
Where "n" would be a negative integer number of bytes before the end of the file. Unfortunately, you would need to know how many bytes to back up.

If you know the largest number of bytes that the last line will have, you could back up that much (or more) and read the remaining bytes:
Code:
set nwdata [read $fileId]
(I would avoid using "newline" as a variable name as it is a keyword).

Then you can find the last linefeed:
Code:
string last "\n" $nwdata
And return the data after that:
Code:
string range $nwdata [string last "\n" $nwdata] end

Or you could use regesp, of course.

_________________
Bob Rashkin
 
Cool buddy! That helps! Great! :)
Thanks a lot once again you'll be starred ;)

Ron
Hours of planing can save weeks of coding
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top