Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!newsfeed00.sul.t-online.de!t-online.de!news.karotte.org!news.musoftware.de!wum.musoftware.de!feeder.erje.net!feeder.eternal-september.org!eternal-september.org!not-for-mail
From: dpb <none@non.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: repetitive counter (GUI)
Date: Wed, 15 Jul 2009 09:18:17 -0500
Organization: A noiseless patient Spider
Lines: 102
Message-ID: <h3kom1$itq$1@news.eternal-september.org>
References: <h3g5v9$6ep$1@fred.mathworks.com> <h3g6rd$58f$1@fred.mathworks.com> <h3g7ie$mr4$1@fred.mathworks.com> <h3g8bd$lin$1@news.eternal-september.org> <h3hbh5$ljn$1@fred.mathworks.com> <h3hgfb$96h$1@news.eternal-september.org> <h3i04f$90p$1@fred.mathworks.com> <h3i1jj$r9o$1@news.eternal-september.org> <h3i1oe$q5s$1@fred.mathworks.com> <h3itgh$cs9$1@fred.mathworks.com> <h3j5kc$9je$1@news.eternal-september.org> <h3k0pa$sg9$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.eternal-september.org U2FsdGVkX18UnJHJFp2KrxUZiWWnU/sLjjUwQdYkgiTCm9zV4FVOsJ2DofgtxrVYL1MdmUAPzULQI9Gyh+cGAjJkd425DtQT5yo2g+gkpe462O23ilnrWBXKqKFpfohm
X-Complaints-To: abuse@eternal-september.org
NNTP-Posting-Date: Wed, 15 Jul 2009 14:21:55 +0000 (UTC)
In-Reply-To: <h3k0pa$sg9$1@fred.mathworks.com>
X-Auth-Sender: U2FsdGVkX18UoDVb3L8+TnwsRVGgVth78eiI856W+mw=
Cancel-Lock: sha1:GdqmzIhtLxt7i1KLd4Q8fMjR1/w=
User-Agent: Thunderbird 2.0.0.22 (Windows/20090605)
Xref: news.mathworks.com comp.soft-sys.matlab:555662


ching l wrote:
...
> ...I'm not sure what you mean by "you increment
> handles.count and then set it to count which will in essence undoes the 
> increment operation." Would you mind to explain a little bit?

That's what the _POSTED_ code did which was NOT the actual code run. 
It's absolutely impossible to debug when provided incorrect 
information... :(

> Anyway the codes should look like this-

I've pared it down to the portion that has to do w/ the counter and 
debugging i/o below...

Note the indenting to emphasize the logical structure; I strongly 
recommend you adopt some sort of similar (but consistent) formatting; 
you will find it will help immeasurably in reading your code.

> handles = guidata(gcbo);
> if(handles.count<=2)
>   handles.count= handles.count+1;
>   count = handles.count
> else
>   set(hObject, 'enable', 'off')
> end
> guidata(gcbo, handles);
> ...
> handles.randValue=299+handles.count;
> play= handles.randvalue
...
> guidata(hObject, handles);
> 
> --------------------
> The results are
> 
> count= 0 play= 300 ;
> count= 1 play= 301 ;
> count = 2 play = 302 ;
> play= 302 ; disable button

OK, I see everything except what generated the "disable button" message? 
  There's nothing in the code above I see that would have done it.

It's clear why everything else is as it is; the counter is 
incremented/displayed for 0,1,2 as is "play".  The line

play= handles.randvalue

is outside the if...else...end construct so it is executed every time 
the function is called w/ the last value of the counter.

As noted, I can only assume you again added the "disable" button" to the 
posting...

> ----------------------
> 
> what I want is
> count= 0 play= 300 ;
> count= 1 play= 301 ;
> count = 2 play = 302 ;
> disable button

See above as to why the other "play =" message appeared.

You'll have to decide what the code is supposed to do once the counter 
has been incremented.

If the real question is there's an additional event generated after you 
think you have disabled the control, I don't know a thing about how ML 
GUIs work at the control level; as noted I don't use anything except the 
command window interface in ML.

If I were debugging I'd do something like

 > handles = guidata(gcbo);
 > if(handles.count<=2)
 >   handles.count= handles.count+1;
 >   count = handles.count
 > else
 >   set(hObject, 'enable', 'off')
 >   disp(['Disabled control'])
 > end
 > guidata(gcbo, handles);
 > ...
 > handles.randValue=299+handles.count;
 > play= handles.randvalue

to get the sequencing documented.

Also, when you post the results of any more testing, simply paste the 
contents of the command window; don't rearrange lines, etc., other than 
perhaps to squeeze out blank lines.  It confuses the issue when the 
code/output obviously don't match; sometimes it's just cosmetic, other 
times as the previous post it changes the meaning entirely and makes the 
whole post worse than meaningless.  The point to be learned is you must 
be precise to have any chance at all of getting meaningful response.  A 
secondary lesson is if you continue to create confusion by not adhering 
to the above, folks will soon tire of going thru the exercise of 
futility and just ignore the thread...

--