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

How to use Form/Window Close Property VFP8

Status
Not open for further replies.

newtofoxpro

Programmer
Sep 16, 2007
301
IN
Code:
SET SAFETY OFF
xcolor ="RGB(0,0,0,255,255,255),RGB(0,0,0,255,255,255),RGB(0,0,0,170,190,223),RGB(0,0,0,170,190,223),RGB(0,0,0,170,190,223),RGB(0,0,0,170,190,223),RGB(240,240,240,40,72,72),RGB(0,0,0,0,0,0),RGB(0,0,0,170,190,223),RGB(0,0,0,255,255,255)"
define window xadd AT 0,0 SIZE 20,70 NAME xaddNAME font 'tahoma',10 color (xcolor)
activate window xadd nosho
move window xadd CENTER
WITH xaddNAME
 .BorderStyle=1
 .ControlBox=.T.
 .Caption='Customer Information'
 .Closable=.t.
ENDWITH
activate window xadd
CLOSE DATABASES
IF !FILE('Customer.dbf')
   CREATE TABLE customer.dbf (Cname c(40), Cadd1 c(40), Cadd2 c(40), Cadd3 c(40), Cadd4 c(40))
   USE
ENDIF
ERASE customer.cdx
USE customer.dbf ALIAS Cust IN 0
INDEX ON Cadd3 TAG one
@ 2  ,0 say 'Name :'    pict '@J' size 1,11
@ 3.5,0 say 'Address :' pict '@J' size 1,11
@ 6.5,0 say 'City :'    pict '@J' size 1,11
@ 8.0,0 say 'Phone :'   pict '@J' size 1,11
DO WHILE LASTKEY()#27
   @ 2.0,12 get CustName default SPACE(40) size 1,40 when get_Alp(2.0,12)
   @ 3.5,12 get CustAdd1 default SPACE(40) size 1,40 when get_Alp(3.5,12)
   @ 5.0,12 get CustAdd2 default SPACE(40) size 1,40 when get_Alp(5.0,12)
   @ 6.5,12 get CustAdd3 default SPACE(40) size 1,40 when get_Alp(6.5,12)
   @ 8.0,12 get CustAdd4 default SPACE(40) size 1,40 when get_Alp(8.0,12)
   READ nomouse
   IF INLIST(LASTKEY(),13,24)
      INSERT INTO Cust (Cname,Cadd1,Cadd2,Cadd3,Cadd4) VALUES (UPPER(CustName),UPPER(CustAdd1),UPPER(CustAdd2),UPPER(CustAdd3),UPPER(CustAdd4))
      RELEASE CustName,CustAdd1,CustAdd2,CustAdd3,CustAdd4
   endif
ENDDO
RELEASE window xadd
SET RESOURCE TO foxuser.dbf
SET RESOURCE ON
RETURN 

FUNCTION get_Alp
****************
PARAMETERS mro,mco

mvar=varread()
@ mro-.1,mco-.5 to mro+1.1,mco+LEN(&mvar)+.5 color RGB(0,0,0)
OutString=&mvar
@ mro,mco get just_temp defa LEFT(OutString,1) size 1,.1
StringBuffer=""
FOR Cnt=1 TO LEN(&mvar)
   READ
   key=LASTKEY()
   IF (key=4 AND LEN(ALLTRIM(outstring))<=cnt)
      OutString=ALLTRIM(OutString)+Stringbuffer
   ENDIF
   DO CASE
   CASE (BETWEEN(key,33,122) AND key#39) OR (INLIST(key,32) AND cnt#1)
      outstring=iif(cnt=1,space(LEN(&mvar)),outstring)
      outstring=STUFF(outstring,cnt,iif(insm(),0,1),proper(chr(key)))
   CASE INLIST(key,13,24)
     _curobj=_curobj+1
     EXIT
   CASE INLIST(key,5,15) &&uparrow
     _curobj=IIF(_curobj=1,1,_curobj-1)
     EXIT
   CASE INLIST(key,27)
     CLEAR read
     EXIT
   CASE key=7 OR key=127                  &&delete, backspace
      outstring=STUFF(outstring,iif(key=7,cnt,cnt-1),1,"")
      cnt=cnt-iif(key=7,1,2)
   CASE key=1 &&home
      cnt=0
   CASE key=19 OR (key=4 AND LEN(ALLTRIM(outstring))>=cnt) &&left, right
      cnt=cnt+IIF(key=19,-2,0)
   OTHERWISE
      cnt=cnt-1
   ENDCASE
   cnt=IIF(cnt<0,0,cnt)
   OutString=PADR(outstring,LEN(&mvar))
   @ mro,mco say PROPER(OutString) size 1,LEN(&mvar)
   @ mro,mco+TXTWIDTH(LEFT(PROPER(outstring),cnt)) say '' size 1,.0
   IF UPPER(mvar)=UPPER("Custadd3") AND !EMPTY(OutString) AND SEEK(UPPER(ALLTRIM(OutString)),'Cust','one')
      @ mro,mco say PROPER(Cadd3) size 1,LEN(&mvar) color RGB(200,200,200)
      @ mro,mco say ALLTRIM(PROPER(OutString))
      @ mro,mco+TXTWIDTH(LEFT(PROPER(outstring),cnt)) say '' size 1,.0
      StringBuffer=ALLTRIM(SUBSTR(Cadd3,LEN(ALLTRIM(OutString))+1,1))
   ELSE
      StringBuffer=""
   ENDIF
   store PROPER(outstring) to &mvar
ENDFOR
@ mro-.1,mco-.5 clear to mro+1.1,mco+LEN(&mvar)+.5
@ mro,mco say PROPER(OutString) size 1,LEN(&mvar)
RETURN

Save above code as customer.prg and RUN.
You will find Small close button. If I close, window disappear but vfp stop working. I want, when I click on <CLOSE> it should run <KEYBOARD CHR(27)>

Above customer.prg's functionality is simple
1) What ever type it appear in proper() format.
2) Use Enter,Uparrow,Dnarrow & ESC to quit
3) In city field if city already exist it appear in fade color and you can select by rightarrow key.
4) Black Box appear on input field.

I am new to VFP8 and trying to migrate my fpw application.

Thank you.
 
And the question is?
What specific issue are you having? (other than re-writting the whole code sequence for VFP, because that would be your job).


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
What specific issue are you having? (other than re-writting the whole code sequence for VFP, because that would be your job). "

My Question is ..

You will find Small close button. If I close, window disappear but vfp stop working. I want, when I click on <CLOSE>

.Closable=.t.

How to manage ?
 
If you are going to re-write this for VFP8, why are you using Foxpro 2.x code?
They don't get along too well.
1.On my system with your code, if I type one letter in the textbox, and hit the close button, it does not close, it just adds the same letter agin in the textbox.
2. At some point in my test, VFP9 crashes.

Either you choose to use VFP8 type programming (Forms and methods) or you may have a better chance posting this question In the Foxpro 1.2 to 2.6 forum

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Newtofoxpro,

First, your code uses a lot of old DOS-style code, such as @/GET and DEFINE WINDOW. Although these commands still work, very few developers still use them, and fewer still would be willing to learn them.

You'd be much better off using more current programming techniques, which in this case includes the form designer and event-handling. Not only will this result in a better program, it will also make it easier for other people to help you with your problems.

Also, it's not particularly helpful to post a large chunk of code, and expect forum members to figure out for themselves what it is supposed to be doing. It would be better if you could explain the actual problem you are having, without all the extraneous information.

I hope you don't mind me pointing these things out to you. I do so only to help you get a better answer to your problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I whole heartedly agree with the above comments.

Quit trying to use old FPD DEFINE WINDOW and @Row/Col methods to create VFP forms.

Use the VFP Form Designer and create your forms the VFP way and then these other problems will either go away or they will become more clear to resolve.

Good Luck,
JRB-Bldr
 
I'll add to the pileup.

The language may be backwards-compatible, but that's the same as compatible with backwards. Don't use deprecated techniques.

I see READ NOMOUSE which is a clause that flatly has no place in a Windows app, and I also see nested READs which were never a good idea except as an application control mechanism. (READ inside the WHEN clause of a GET? That's SUICIDE!)

Your example would be too clever by half in 1990.

Use today's tools. A form's DataEnvironment will take care of opening your table, you can then drop fields from the DE to the form and they're properly bound. The close box will work just fine, and you haven't written a single line of code.

If you *insist* on that keystroke handling you're currently doing inside the READ WHEN, use the form's Keypress method, which fires automatically once you've turned on KeyPreview.

You're working *way* too hard.
 
More than likely I have already given you this link to the free VFP on-line tutorials (since I reference it often to those who are new to VFP).

But, just in case I missed you, you might get some benefit from looking at:

Good Luck,
JRB-Bldr
 
Thank you all
Already I told that I am new to VFP8. So I don't know the power of Form & Methods. I could ask for just how to implement .Closable=.t. with define window.

A have kept question with too long CODE (SORRY) to know what is possibilities in Vfp.

"If you *insist* on that keystroke handling you're currently doing inside the READ WHEN, use the form's Keypress method, which fires automatically once you've turned on KeyPreview."

This paragraph boost my confidence. I found my PATH.... 1) Create form with object 2) form's keypress method would take care this job.

Thanks & Best Regards. I will try my level best.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top