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

Error 2012 when using arrow key to change page 2

Status
Not open for further replies.

kelunaboy

Programmer
Jun 26, 2002
42
US
I am getting Program Error 2012 "Cannot call SetFocus from within a When, Valid, RangeHigh or RangLow event." when the left or right arrow key is used to move between pages on a pageframe.

Does not occur when using mouse click to select page on pageframe.

Error goes away if form Window Type is changed to Modal (but other things break...)

With Set Step On the "Read Events" command in my main program is where the error occurs.

The error occurs on a form with only default methods on pageframe and pages, and also occurs on a form with defaults on pageframe and one user procedure on Activate Event for each page.

Sample code in .prg

DO FORM forms\frmvrmain NAME frmMain
READ EVENTS
Cancel

*** ButtonGroup1 is main menu selections on vrmain form
PROCEDURE ButtonGroup1
DO Case
CASE frmMain.Commandgroup1.Value = 1
*** vrSelect
frmMain.Hide
DO programs\vrSelect

CASE frmMain.Commandgroup1.Value = 2
CASE frmMain.Commandgroup1.Value = 3
CASE frmMain.Commandgroup1.Value = 4
CASE frmMain.Commandgroup1.Value = 5
CASE frmMain.Commandgroup1.Value = 6
ENDCASE
ENDPROC

My style of programming is rooted in FoxPro 2.6a. Generally I run a .prg which calls a form. For debugging ease I prefer to place all the code for a form in the calling .prg, instead of hidden in a form method. When the user switches to another function I .Hide the form and call another .prg

Thank you,
Alan
 

I am getting Program Error 2012 "Cannot call SetFocus from within a When, Valid, RangeHigh or RangLow event." when the left or right arrow key is used to move between pages on a pageframe.

This would indicate to me that you are trying setfocus() in the wrong event. Where is your Setfocus()


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Aloha Mike,

Thank you for your reply. As far as I know I am not trying to do a setfocus(). My form is displayed and works fine unless the left or right arrow key is used.

I am new to Object programming so please bear with me. My understanding of SetFocus() is that each Page on the Pageframe on my form has this Property, and I have left all of them at the default setting. The only controls on the form are textboxes.

Thank you,
Alan
 
Once again I may have solved my problem by trying different things, but if I might pose a few questions it would help my understanding.

Previously I started my program with a Login form that was Modal. It called another form (the main menu) that was Modeless and I issued a Read Events command after the main menu. I never released the Login form. By moving the Read Events to the Login program and changing the Login form to modeless, the error has gone away.

Question:

In general is it a sound practice to start the Read Event in the first program, use only Modeless forms, and use the Hide/Show property for form control?
 

The way write programs is:

[ol][li]I first load the login form (Modeless). I make this modeless because modal means you want to force the user to input his username and password before he does anything else, but at this point there is nothing else (the menu isn't loaded yet).[/li]
[li]Once the user is validated, you release (Not hide, you don't need this form anymore) the login form and load the menu, and put your Read Events right after loading the memu.[/li][/ol]

P.S. I use a Modal form only in the case of a small pop-up form that requires the user input. For example when the user needs to search for a record, If it was modeless, it could cause an error in the user does not input a value and decides to click somewhere else in the application.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
In general what I think Mike is saying is that the READ EVENTS is the last thing you execute in the start up of your application, not necessarily just after the menu is run.

Many developers have a main program to configure the environment, open tables if using local data, initiate various objects to perform tasks like form management, registry management, application global services, run the menu, then do the READ EVENTS. The sequence of things done before the READ EVENTS is specific to your needs.

After the READ EVENTS is the clean up code since this code will not run until the CLEAR EVENTS is executed.


_RAS
VFP MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top