another onkeypress question

In this category you can exchange your programming questions and solutions.
Post Reply
Fazer
Posts: 30
Joined: Tue Apr 29, 2008 12:43 pm

another onkeypress question

Post: # 256Post Fazer
Tue May 20, 2008 5:56 am

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 !


PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

another onkeypress question

Post: # 257Post PaPi
Tue May 20, 2008 7:21 am

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.

Fazer
Posts: 30
Joined: Tue Apr 29, 2008 12:43 pm

another onkeypress question

Post: # 258Post Fazer
Tue May 20, 2008 7:45 am

Thanks!
This is an important advice!

Fazer
Posts: 30
Joined: Tue Apr 29, 2008 12:43 pm

another onkeypress question

Post: # 259Post Fazer
Thu May 29, 2008 7:05 pm

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 ?

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

another onkeypress question

Post: # 260Post Marco
Thu May 29, 2008 8:02 pm

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

Fazer
Posts: 30
Joined: Tue Apr 29, 2008 12:43 pm

another onkeypress question

Post: # 261Post Fazer
Fri May 30, 2008 5:46 am

Some things are so easy - if you know them !

Thank you so much!

Post Reply