Page 1 of 1

another onkeypress question

Posted: Tue May 20, 2008 5:56 am
by Fazer
In a former thread with the title "onkeypress question"

(http://fnxbasic.com/yabb/YaBB.pl?num=1210785692)

YaBB Administrator gave me an example, I added some lines:

`--------------------------------------------------
`begin of Code
object f as form
? ?object b as button
? ? ? ? ? ? ? ? ?onkeypress=kp
? ? ? ? ? ? ? ? ?OnClick=mytext
? ? end object
end object

f.showmodal

sub kp(key as integer)
? ?` If key=49 then mytext ? ? ` ?<--- please uncomment
? ? showmessage str$(key)
end sub

sub mytext()
showmessage "This is a Text"
end sub
` End of Code
`---------------------------------------------
Buts works fine, but if you uncomment the marked line ( "If key=49 then mytext" )
then you will get the following error message:

"error:22 line: 10 variable already used"

What is wrong here ? ?I don`t understand, why there is this error message !


another onkeypress question

Posted: Tue May 20, 2008 7:21 am
by PaPi
Fazer!
The call of a subroutine require the parethesis:
   If key=49 then mytext()  
Note: but, in the object definition NOT! This is not error, it is a convention

PaPi

ps:  Otherwise, although the fnxbasic help has some errors, but, this help is nessesary -
I am registering  for me this errors  for a long while...   ... and the author work upon it and the new version of fnxbasic.

another onkeypress question

Posted: Tue May 20, 2008 7:45 am
by Fazer
Thanks!
This is an important advice!

another onkeypress question

Posted: Thu May 29, 2008 7:05 pm
by Fazer
Now the  keydown-function works in my program, but there must be something wrong with the key code numbers.
( see "key table" in the help file).

The key code table is identical with the Delphi key codes if you change the hexadecimals to decimals, but it didn`t work completely correct in fnxbasic!

example: in the table of the help file there is the integer key value "78" for key "n", but it doesn`t work. But with my computer the "n"-key is in my program represented by the integer "110", the same is for the keys "p" = 111 and  "p" = 112.

The number keys "0" ... "9" are correct: codes 48..57.

I have not checked all keys!

Had anybody  a similar problem ?

another onkeypress question

Posted: Thu May 29, 2008 8:02 pm
by Marco
hi
I think you must use the asci keycode,
n=110 but
N=78

for windows asci keys n and N are both 78.
if you want to detect both  on the same time you can do

key=asc(ucase$(chr$(key)))

best regards

another onkeypress question

Posted: Fri May 30, 2008 5:46 am
by Fazer
Some things are so easy - if you know them !

Thank you so much!