New topic: 

Question About Exit [Solved]

<http://forums.realsoftware.com/viewtopic.php?t=30546>

       Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic         Author  
Message       rbasic20091005153           Post subject: Question About Exit 
[Solved]Posted: Sun Oct 18, 2009 10:25 pm                               
Joined: Sat Apr 04, 2009 5:10 pm
Posts: 353              Hola,

I'm sorry if this question has been raised.  I searched this place with 'Exit' 
and got 80 pages of hits.  And there's no way of my reading all of them.

I use Exit Sub and Exit Function a lot.  I always wonder if there's anything 
that is more appropriate in some situations?  Suppose that I have 2 
pushbottons, PushButton1 and PushButton2.

PushButton1's Action goes

Code:PushButton2.Push
Message "Hello."

And PushButton2's Action goes

Code:Dim i,n As Integer
n=0
For i=0 to ListBox1.ListCount-1
  If ListBox1.CellCheck(i,0)=True then
  n=n+1
  End if
Next i

If n>5 Then
  MsgBox "You can select up to 5 rows at a time."
  Exit Sub
Else
End if
..
..
..



If the user selects more than 5 rows on ListBox1 and pushes PushButton1, then 
he or she will see the warning message.  The application will escape from 
PushButton2's Action but will resume with PushButton1's Action.  Inevitably, he 
or she will get the Hello message.  Is there anything stronger than Exit Sub so 
that the application will escape from PushButton2's Action and will not return 
to PushButton1's Action?

Thank you for your advice.

Tom     
_________________
Mac OS X 10.5.6/REALBasic 2008 R5.1
I say 'no' to MBS plug-ins.  I boycott them.     

    Last edited by rbasic20091005153 on Sun Oct 18, 2009 11:52 pm, edited 1 
time in total.   
                            Top               npalardy           Post subject: 
Re: Question About ExitPosted: Sun Oct 18, 2009 10:31 pm                        
Joined: Sat Dec 24, 2005 8:18 pm
Posts: 5341
Location: Canada, Alberta, Near Red Deer              Yeah
Dont write code this way 
This quick sample below should give you an idea of how to rearrange your code 
so you can tell if the user got the error an NOTHING more should happen

PushButton1's Action goes
Code:
if CallCommonProcessingMethod() = false then exit
Message "Hello."


PushButton2's Action goes
Code:
if CallCommonProcessingMethod() = false then exit



Code:Function CallCommonProcessingMethod() as boolean
  Dim i,n As Integer
  n=0
  For i=0 to ListBox1.ListCount-1
  If ListBox1.CellCheck(i,0)=True then
  n=n+1
  End if
  Next i
  
  If n>5 Then
  MsgBox "You can select up to 5 rows at a time."
  return false
  End if
  
  return true
  
     
_________________
My web site Great White Software
RBLibrary.com REALbasic learning  
                            Top               rbasic20091005153           Post 
subject: Re: Question About ExitPosted: Sun Oct 18, 2009 11:07 pm               
                
Joined: Sat Apr 04, 2009 5:10 pm
Posts: 353              Thanks.  I guess there's nothing simpler like

Exit Window     
_________________
Mac OS X 10.5.6/REALBasic 2008 R5.1
I say 'no' to MBS plug-ins.  I boycott them.  
                            Top               npalardy           Post subject: 
Re: Question About ExitPosted: Sun Oct 18, 2009 11:32 pm                        
Joined: Sat Dec 24, 2005 8:18 pm
Posts: 5341
Location: Canada, Alberta, Near Red Deer              Nope
You're not exiting the window so "Exit Window" would not be right in any event

Write code that makes it easy for you to maintain, control and extend
If code could arbitrarily "jump out of" on spot through all the bits that got 
called anything that got called would have to know what called it in order to 
make decisions about what to jump out of

Don't design code that requires that kind of knowledge as it's inherently 
fragile and trouble prone     
_________________
My web site Great White Software
RBLibrary.com REALbasic learning  
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to