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

on key label with procedure?

Status
Not open for further replies.

hyonos

Technical User
Apr 2, 2003
46
0
0
IT
how can i do this ?

lform="brw_test"
lform2="brw_test2"

ON KEY LABEL F8 runform with lform
ON KEY LABEL F9 runform with lform2

PROCEDURE runform
parameter lform
DO forms "forms\"+&lforms with 1
ENDPROC

 
i have found

&& mycommand si variabile with command to execute
mycommand="mesagebox('more command')"+chr(13)+;
"do forms myform"

ON KEY LABEL F9 EXECSCRIPT("&mycommand" )
 
hyonos

This works for me.

lform="addresses.scx"
On Key Label F8 Do runform With lform

Procedure runform
Parameter lform
Do Form ".\forms\"+lform WITH "1"
Endproc


Mike Gagnon

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

can i save myscrit in a memo field and after add it i "on key label" ?

for example
mytable.myscript is a memo
in memo field i write
wait window "test"
do form myform

and do:

ON KEY LABEL F9 EXECSCRIPT(mytable.myscript)

can i do this?
 
hyonos,
I just tried this code in VFP 8.0 (and 7.0 SP1), and it works fine.
Code:
CREATE CURSOR mytable (myscript M)
INSERT Blank
replace myscript WITH [wait window "test"]+CHR(13)+CHR(10)+[MESSAGEBOX("test", 0, "Title")]

ON KEY LABEL F9 EXECSCRIPT(mytable.myscript)
Usually if you know what you want, all you need to do is try it. (One of the advantages of the interactive environment of VFP! :))

Rick
 
In the init of payment scr I put
ON KEY LABEL F6 payment.movcur()
movcur is a method in the payment scr
 
:(

ON KEY
SCAN
hot=ALLTRIM(hotkey.hotkey)
ldo=ALLTRIM(hotkey.do)
WAIT WINDOW ldo
ON KEY LABEL &hot execscript("&ldo")
ENDSCAN


this code only work with first 2 record... why ?

hotkey is a table
hotkey.do is memo

i have 3 record

1) hotkey.hotkey=F8
hotkey.do=do form myform1
2) hotkey.hotkey=F9
hotkey.do=do form myform2
3) hotkey.hotkey=F12
hotkey.do=wait window "hallo"
wait window "world"

1° and 2° record work fine, but 3° give me an error:
"Function name is missing )."
why?

i have try to replace 3° record with
wait window mypublicvar

and word but if i try
wait window mypublicvar
wait window mypublicvar

don't work...

can anyone help me?
 
The trouble is your use of quotes....


When:
Code:
3) hotkey.hotkey=F12
   hotkey.do=wait window "hallo"

This:
Code:
ON KEY LABEL &hot execscript("&ldo")

Ends up being:
Code:
ON KEY LABEL &hot execscript("wait window "hallo"")

And the quotes are all screwed up. What you could change to is this in the loop:
Code:
ON KEY LABEL &hot execscript([&ldo])

or, better yet:
Code:
ldo=ALLTRIM(hotkey.do)
ldo=StrTran(lDo,["],["+'"'+"])  && make quotes safe
ON KEY LABEL &hot execscript("&ldo")


crpryor:
In the init of payment scr I put
ON KEY LABEL F6 payment.movcur()
movcur is a method in the payment scr

This is a problem, unless in your "payment screen" you define "payment" as a global variable.

safer would be this:
Code:
ON KEY LABEL F6 iif( vartype(_screen.activeform='O' and PEMSTATUS(_screen.activeform,'movecur',5), _SCREEN.ActiveForm.MoveCur(),'')

I usually isolate all such ON KEY's that must access a form to only use a single method, and all call that method with parameters. Then that method (on, perhaps, a global object that always exists) can execute several lines of code to make the ON KEY completely safe.
 
great tnx !

if memo have multiple line, this code don't work.

memo like:
wait window "hallo"
wait window "world"


i have try this:

SCAN
hot=ALLTRIM(hotkey.hotkey)
ldo=ALLTRIM(hotkey.do)
ALINES(myarray,ldo,.F.,CHR(13))
IF ALEN(myarray)=1
&& this code work
ldo=StrTran(ldo,["],["+'"'+"]) && make quotes safe
ELSE
ldo=""
FOR x=1 TO ALEN(myarray)
&& this IS WRONG
ldo=ldo+StrTran(myarray(x),["],["+'"'+"]) && +CHR(13)+CHR(10)
NEXT
ENDIF
ON KEY LABEL &hot execscript("&ldo")
ENDSCAN

but don't want work :(
 
i have find solution ! :)

SCAN
hot=ALLTRIM(hotkey.hotkey)
ldo=ALLTRIM(hotkey.do)
ldo=StrTran(ldo,["],["+'"'+"]) && make quotes safe
ldo=STRTRAN(ldo,CHR(13),"")
ldo=STRTRAN(ldo,CHR(10),["+CHR(13)+"])
ON KEY LABEL &hot execscript("&ldo")
ENDSCAN



tnx ALL !!
 
The trouble now is stemming from the fact that you're trying to do a multi-line statement. You can't macro-expand a variable that has CR+LF's in it, or else there'd be no reason for EXECSCRIPT ;)

This'll work, but is kinda messy:
Code:
SCAN
  hot = ALLTRIM(hotkey.hotkey)
  ldo = ALLTRIM(hotkey.do)
  ldo=StrTran(ldo,["],["+'"'+"])  && make quotes safe

  * Determine if we need a public var
  ALINES(myarray,ldo,.F.,CHR(13))
  IF ALEN(myarray)=1
    * this code works
    ON KEY LABEL &hot execscript("&ldo")
  ELSE
    * This Will Work
    * (the sys(2015) starts with a "_" so we don't need it here)
    lMacroVar = 'gc_macro'+sys(2015)
    PUBLIC &lMacroVar
    &lMacroVar = ldo
    ON KEY LABEL &hot execscript(&lMacroVar)
  ENDIF 
ENDSCAN

Now, When you release your on keys, also do this:
Code:
RELEASE ALL LIKE gc_macro_*

(If you don't, after a while you might run out of memory variables)
 
You posted your solution while I was writing mine... I wouldn't have expected a lone CHR(13) to work the way you describe it to... (as not dividing lines in the macro replacement and call to EXECSCRIPT, yet properly dividing lines inside EXECSCRIPT)

I'd be worried whether it would continue to work properly in future VFP versions,

But, either way, you've got something that works!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top