SWITCH problem - need thoughts

new topic     » topic index » view thread      » older message » newer message

Version 4.01.00 Windows 7 pro

I have just spent many hours trying to figure this one out. It just doesn't make sense to me (!). I include the code however only the switch block needs attention. "cat_sel_cancel_btn" (also called "cancel btn" in the printout) is a constant defined at the beginning of the program and the value is printed just after it is set as line 1 in printout. line 2 is the value just after entering the procedure. Line 3 is the value of a global atom set by the event handler which I also set evntownr to to remove any possible change in EventOwner affecting this test. Lines 4 & 5 are the values of "cancel btn" further down the switch. All looks OK. Now, when one arrives at "case cat_sel_cancel_btn then" (you will notice that evntownr and cat_sel_cancel_btn are equal) it should execute this case block, printing something with "point 5" in it; however, it continues to the "case else" and now the value of the CONSTANT "cat_sel_cancel_btn" HAS CHANGED! In the following code pf() is a print procedure which does nothing but print what's in the argument. I rewrote the code to use if/elsif statements instead of using switch blocks. It works perfectly. Now, I didn't think about this at the time (brain dead!) but, I had this very same problem earlier in the program with another switch statement. Replaced that one with if/elsif and moved on. In any event I think SWITCH has a real problem. It seems to have been plagued with problems since its introduction. Please, point out my error, just one word will do!

Thanks & Regards, jd

Here is the printout:

line #1  point a - cancel btn  => 9247618 
line #2  point 1 - cancel btn  => 9247618 
line #3  Event owner @ point 2A  => 9247618 
line #4  Point 2B evntownr  => 9247618 
line #5  point 2C - cancel btn  => 9247618 
line #11  cancel btn @ point 6A  => 9247616  <====  Here is the problem! 
line #12  Point 6B evntownr  => 9247618 

global constant cat_sel_cancel_btn = Control(Button,"CANCEL",200,125,75,35) 
	pf(cat_sel_cancel_btn,"line #1  point a - cancel btn => ")	 

Switch block in question:

public procedure service_category(atom box)		--box is the event owner 
							--which is the col 7 box in grid 
sequence box_txt = GetText(box) 
atom evntownr 
	pf(cat_sel_cancel_btn,"line #2  point 1 - cancel btn => ") 
	while True do 
		WaitEvent()			        --only two things can happen "cancel Button" or 
							--a category picked.  Everything else is ignored. 
		evntownr = EventOwner	                --a global returned by a procedure elsewhere 
		if Event = Click then 
			pf(EventOwner,"line #3  Event owner @ point 2A => ") 
			pf(evntownr,"line #4  Point 2B evntownr => ") 
			pf(cat_sel_cancel_btn,"line #5  point 2C - cancel btn => ") 
			switch evntownr do 
				case cat_box then   
					pf(cat_box,"line #6  point 3 - cat_box = ") 
					pf(evntownr,"line #7  evntownr => ") any_key() 
					sequence cat_txt = GetItem(cat_box) 
				case cat_sel_cancel_btn then 
					pf(cat_sel_cancel_btn,"line #8  cancel_btn @ point 5A = ") 
					pf(box,"line #9 Point 5B box = ") 
					pf(evntownr,"line #10 evntownr => ") any_key() 
				case else 
					pf(cat_sel_cancel_btn,"line #11  cancel btn @ point 6A => ") 
					pf(evntownr,"line #12  Point 6B evntownr => ") 
			end switch 
		end if	 
	end while 
end procedure 
new topic     » topic index » view thread      » older message » newer message


Quick Links

User menu

Not signed in.

Misc Menu