Normal Topic ThrowFocus() vs. GoTo (Read 869 times)
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
ThrowFocus() vs. GoTo
Jan 23rd, 2006 at 1:52am
Print Post Print Post  
From the beginning I have been hearing that I should be using ThrowFocus() instead of GOTO.  It has been explained that GOTO was provided as a carryover from Q&A for consistency.

But I recently found that I need to change my thought process and not always use ThrowFocus() instead of GOTO.  There is a big distinction between the two.  And I believe that GOTO has its place and purpose.

GOTO will change focus and programming control instantly from that line in the programming code.
ThrowFocus() does not do that.
ThrowFocus() allows the rest of the programming to continue and does not change focus and programming control until the rest of the programming codes has been executed.

This distinction is critical.  I had some code with ThrowFocus() but had unexpected results for me.  That is because I was expecting program control to change at that part of the code, but instead it continued with the following lines. That is not what I expected.

This difference can be seen like this:
Make text elements named LE1 and LE2 and LE3
Make a text element named LE3.
Put the following code in LE1, On Element Exit.
Code
Select All
LE2 += "Line 1" + " - "
//ThrowFocus(LE3)
GOTO LastName
LE2 += "Line 2" + " - "
LE2 += "Line 3" + " - " 

Move the cursor to LE1, and press TAB to exit the element.
This will result in LE2 will say Line 1 and focus will go to LE3.
Now comment out GOTO line and remove comments // from the ThrowFocus line, and repeat exit from LE1.
This will result in LE2 will say lines 1,2,3 and focus will go to LE3.  Totally different results.

The Programmers Guide manual is very clear in explaining the difference.
Quote:
Moves to layout element when current program has finished.
But I had been listening to instructions here on the forum vs. RTFM, accepting the recommendations blindly, with faith. But the forum recommendations made it sound like they were interchangeable.

Two lessons learned: 
1.  ThrowFocus() is not a replacement for GOTO.  They both have their purpose and behave differently.
2.  No matter who provides recommendatioins on the forum, we should go back to the manuals and read the content for full clarification. 
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: ThrowFocus() vs. GoTo
Reply #1 - Jan 23rd, 2006 at 2:31am
Print Post Print Post  
There is a difference between them and that is why it is so important to always use Throwfocus and to never use goto.

If you need to prevent code from being run, use a conditional.

If the manual says otherwise, the manual will be corrected.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: ThrowFocus() vs. GoTo
Reply #2 - Jan 23rd, 2006 at 4:33pm
Print Post Print Post  
Hello Bob,

You know how we preach against the use of STOP? Well Goto is the same way. Using Goto to stop additional code from running is a big No-No and is never recommended under Any circumstances. It can, in every case I have ever seen, be replaced by a ThrowFocus() and a conditional.

If you as the programmer are counting on Goto's nature to not run the rest of the code after the Goto, you need to re-design that code as Goto may not always do that, not to mention it is a horrible programming practice.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: ThrowFocus() vs. GoTo
Reply #3 - Jan 23rd, 2006 at 5:13pm
Print Post Print Post  
Well, I have been using ThrowFocus() until recent issues in subForm OnExit and OnEntry this past week.

I think that it has always been used conditionally.  But when ThrowFocus appeared not to be working, I tried using GOTO to see if it behaved any differently.  In reading the manual, I saw the distinction, and did a little test as submitted above.  I guess I erred in not using a conditional in the test.

End result was that GOTO vs. ThrowFocus() focus did not fix the problem anyway.  And an interesting thing that did happen however was that if I had a WriteLn following the ThrowFocus, then the focus would not change.  Even after closed the WriteLn popup window.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: ThrowFocus() vs. GoTo
Reply #4 - Jan 23rd, 2006 at 5:19pm
Print Post Print Post  
Hello Bob,

Using Writeln() to try and figure out focus events is not going to work as WriteLn() is going to take the focus and cause focus events. I use FileWrite() and/or @Msg() as neither of those cause focus events.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: ThrowFocus() vs. GoTo
Reply #5 - Jan 23rd, 2006 at 5:38pm
Print Post Print Post  
Yes, I agree, better to do that.  But when troubleshooting a problem, sometimes you start trying anything to ID cause of trouble. 

That is what I did here, and found that using GOTO vs ThrowFocus allowed focus to change with WriteLn because it jumped out of the program right away. 

But you bring up a good point re troubleshooting. 
If you are using WriteLn after a ThrowFocus() then the ThrowFocus() will not work.  Must put the WriteLn before the ThrowFocus or use @Msg/WriteFile.  @MsgBox will also cause ThrowFocus to be lost, so use  @Msg vs. @MsgBox.



  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: ThrowFocus() vs. GoTo
Reply #6 - Jan 23rd, 2006 at 5:57pm
Print Post Print Post  
Quote:
But you bring up a good point re troubleshooting. 
If you are using WriteLn after a ThrowFocus() then the ThrowFocus() will not work.  Must put the WriteLn before the ThrowFocus or use @Msg/WriteFile.  @MsgBox will also cause ThrowFocus to be lost, so use  @Msg vs. @MsgBox.


Putting the WriteLN() before the ThrowFocus() will also cause some focus issues if the Window is not already open. The most reliable way to debug with Writeln() is to have it open by writing something to it, on an event that you are not testing, Such as having a command button write out some piece of data. Then leave that window open and out of the way, Do not minimize it. When it is open other WriteLn() calls do not move focus to the WriteLn() window, which is actually called the "Slate" if you wanted to know. But again there are better ways to debug focus events then to use WriteLn().

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: ThrowFocus() vs. GoTo
Reply #7 - Jan 23rd, 2006 at 6:50pm
Print Post Print Post  
Good idea to already have the Slate open.  Grin

Thanks for that reminder.

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged