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

How do i put the cursor to textbox? 1

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
585
PH
Good day everyone.... Please help...

I have 5 pages in may pagframe, I need to put the cursor to my text1 to get input eveytime i run the form... shown are excerpts from my program... but every time i run the code it always tells "cannot change the modality of a visible form" What is the meaning of this?

PROCEDURE Init

SET TALK OFF
SET BELL OFF
SET CENTURY ON
SET CONFIRM OFF
SET SAFETY OFF
SET ECHO off

_screen.visible = .f.

_screen.borderstyle = 2

_screen.backcolor = rgb(0,0,0) && black

SELECT 3
USE smsrec exclusive ALIAS rek

SELECT 2
USE payments exclusive ALIAS pay
INDEX on idnum TO pidnumx

SELECT 1
USE sms exclusive ALIAS tsulat
INDEX on idnum TO idnumx

SET relation TO idnum INTO pay

thisform.pageframe1.page1.Activate

WITH thisform.pageframe1.page1
.text1.setfocus()
ENDWITH

ENDPROC
 
The error message has got nothing to do with setting the focus. Your code for setting the focus appears to be correct.

The message indicates that you are trying to change the form's WindowType property after you have made the form visible. You might be doing this by explicitly setting its WindowType, or by calling its Show method. The code in your Init method does not show either of those cases, so you are presumably doing it at some later point. (Keep in mind that the form is invisible while the Init is executing, and becomes visible when the Init terminates.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
By the way, I remember from another thread that your form is a top-level form: it is intended to be used when the main VFP window (_SCREEN) is hidden. If at any point you are trying to change it to a modal form (one in which the WindowType is 1, or which you are calling Show(1)), then that won't work. A top-level form must be modeless.

The solution is to look for the code that is either setting the form's WindowType or calling its Show method. Once you have found it, ask yourself if it really needs to be there, and if it is doing what you intended.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks mike...

i found already found the error... i set the form to 2.... however, when i run the program, i still need to click the output form for it to be activated. How can i set it that when i run the program the output would have the cursor blinking at the TEXT1 as I run the program?

LOCAL oForm as Form

oForm = CREATEOBJECT("FormSMS")
oForm.Show(2)
READ events
_screen.Visible = .t.

RETURN

.....

.....

.....

PROCEDURE Init

SET TALK OFF
SET BELL OFF
SET CENTURY ON
SET CONFIRM OFF
SET SAFETY OFF
SET ECHO off

_screen.visible = .f.

_screen.borderstyle = 2

SELECT 3
USE smsrec exclusive ALIAS rek

SELECT 2
USE payments exclusive ALIAS pay
INDEX on idnum TO pidnumx

SELECT 1
USE sms exclusive ALIAS tsulat
INDEX on idnum TO idnumx

SET relation TO idnum INTO pay


thisform.pageframe1.page1.activate

WITH thisform
STORE .t. to .image1.visible, .image2.visible
ENDWITH

WITH thisform
STORE .f. to .label5.visible
ENDWITH

WITH thisform.pageframe1.page1
.text1.setfocus()
.text1.REFRESH()
ENDWITH

ENDPROC
 
Mandy,

Are you saying that you are successfully placing the cursor in the textbox, but that the form itself needs to be activated, that is, it needs to be brought to the front? If that's right, youi should put the following code in the form's Init:

Code:
DECLARE INTEGER SetForegroundWindow IN WIN32API INTEGER
SetForegroundWindow(thisform.HWnd)
CLEAR DLLS "SetForegroundWindow"

This is a fairly common problem with top-level forms.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
hi mike!! it worked like magic!!! Thank you so much!! You never fail to amaze me mike.... God Bless.....
 
Glad to have been able to help, Mandy. Good luck with the rest of the project.

Could I make a couple of observations regarding your code. First, I see that you are changing _SCREEN's BackColor and BorderStyle. Those settings will do no harm, but they will have no effect, because _SCREEN is invisible at that point.

More importantly, you are executing INDEX ON commands immediately after opening each table. This is a common mistake among newcomers to FoxPro. The point is that you only need to create an index once, when you first create the table. After that, the index will remain active and will be kept up to date, with no action on your part. Although re-creating the index each time does no great harm, it is a time-consuming operation and will slow down the opening of your form. Also, because you need exclusive use of the table in order to index it, you risk have errors later on when trying to do other things with the table.

If you need a specific index key to be in force (for example, IDNum in your Payments table), you should execute ORDER BY after opening the table. And remove the keyword EXCLUSIVE from your USE commands.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks so much mike.... i'll take note all of it and do it... i have been programming years with fox base... in vfp9 just a newbie... but i manage to solve some of the most complicated problems and errors with your help Mike and Olaf and other members of this forum.... i really really appreciate everything that you do, it makes me love programming with vfp more.... My project is almost done 99%!! and thats because of you all.... thanks and God bless!
 
This article is quite old, but it was written specifically for people new to VFP who'd been working in the Fox world.
It's a guide to what topics are more important to learn as you make the move. Sadly, the articles that were referenced in the sidebar (which I haven't included on the site) mostly aren't available online, but there is plenty of VFP material out there.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top