Author Topic: on key(11)  (Read 1217 times)

0 Members and 1 Guest are viewing this topic.

Offline Theo

  • Newbie
  • Posts: 5
    • View Profile
on key(11)
« on: May 07, 2020, 08:53:37 am »
someone a solution for on key (11). I have a program that uses on key (11) so that I can go up one screen. Now that program only works once. so I can only press on key (11) once, after that it no longer works.
on key (11) gosub (linenumber): on key (11) on
rem gosub linenumber
my program lines
return (to a line number)

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: on key(11)
« Reply #1 on: May 07, 2020, 09:29:37 am »
Works right for me:

Code: QB64: [Select]
  1. n = 11
  2.  
  3.     KEY(n) ON
  4.     ON KEY(n) GOSUB test
  5.  
  6.  
  7. test:
  8. KEY(n) OFF
  9. PRINT "UP Pressed"
  10.  
  11.  

Offline Theo

  • Newbie
  • Posts: 5
    • View Profile
Re: on key(11)
« Reply #2 on: May 08, 2020, 11:40:37 am »
I loaded this program from you into qb64 and I can only go back one screen. After that, it seems that the up arrow key no longer works. How often I press the up arrow key I don't get any higher, or in the case of your program no "up pressed"

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: on key(11)
« Reply #3 on: May 08, 2020, 01:42:54 pm »
I test it under QB64 IDE 1.4 to IDE 0.978 and works well under all versions. Try rewriting n to n = 10 and then try my program with pressing F10, if it so works or not. Maybe it is something with keyboard mapping. Under QB64 exists many alternatives for key (11).

 
key11.JPG

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: on key(11)
« Reply #4 on: May 08, 2020, 03:41:57 pm »
Hi
about Fkey11 and Fkey12
the code on Key GOSUB doesn't work....
I think that this is for IT keyboard, I have tested the code both on a TOSHIBA satellite both on a HP notebook. Also using USB keyboard the result is not different... nothing!
But if I change n to the other values it runs very well.
Programming isn't difficult, only it's  consuming time and coffee

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: on key(11)
« Reply #5 on: May 08, 2020, 05:02:24 pm »
Hi TempodiBasic,

For keys F11 is n = 30, for F12 is n = 31. 11 is arrow up.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: on key(11)
« Reply #6 on: May 08, 2020, 06:09:37 pm »
@Petr
you're right man
LOL I have fused my memory block!
:-)

it works all right on my Toshiba pressing the right key ! LOL again.
Programming isn't difficult, only it's  consuming time and coffee

Offline Theo

  • Newbie
  • Posts: 5
    • View Profile
Re: on key(11)
« Reply #7 on: May 13, 2020, 08:04:01 am »
Sorry it don't work.I added an attachment with my program.
Who can give me a solution.
Thank you
« Last Edit: May 14, 2020, 08:49:47 am by Theo »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: on key(11)
« Reply #8 on: May 13, 2020, 01:23:25 pm »
See row 1340. YOU DO NOT USE KEY() statement, but INKEY$. You have some connection there using variables, but I really don't know more details about it, you have too many GOTO and GOSUB. This error occurs in this part of the program. This is really GOSUB / GOTO crazy.

You can use this me function for reading text files using arrows (+ enter return as value string in actual row)

Code: QB64: [Select]
  1. 'easy text file reader + arrows support (Enter ends it)
  2.  
  3.  
  4. SCREEN _NEWIMAGE(130, 25, 0)
  5. value$ = ReadFile("0.txt")
  6. COLOR 0, 15
  7. PRINT "Returned is: "; value$
  8.  
  9.  
  10. FUNCTION ReadFile$ (FileName AS STRING)
  11.     IF _FILEEXISTS(FileName$) THEN
  12.         ff = FREEFILE
  13.         OPEN FileName$ FOR INPUT AS ff
  14.         REDIM VF(1) AS STRING, i AS LONG
  15.         'load file to memory
  16.         i = 1
  17.         WHILE NOT EOF(ff)
  18.             LINE INPUT #ff, VF(i)
  19.             i = i + 1
  20.             REDIM _PRESERVE VF(i) AS STRING
  21.         WEND
  22.         CLOSE ff
  23.  
  24.         StartPosition = 1
  25.         EndPosition = StartPosition + 22
  26.         Current = 1
  27.  
  28.         DO UNTIL in$ = CHR$(13) 'do until ENTER is NOT pressed
  29.             in$ = INKEY$
  30.             SELECT CASE in$
  31.                 CASE CHR$(0) + CHR$(72): Current = Current - 1 'arrow up
  32.                 CASE CHR$(0) + CHR$(80): Current = Current + 1 'arrow down
  33.             END SELECT
  34.  
  35.  
  36.  
  37.             IF Current > 22 THEN
  38.                 Current = 1
  39.                 IF EndPosition < UBOUND(vf) THEN
  40.                     StartPosition = StartPosition + 22
  41.                 END IF
  42.             END IF
  43.  
  44.             IF Current < 1 THEN
  45.                 IF StartPosition > 22 THEN
  46.                     StartPosition = StartPosition - 22
  47.                     Current = 22
  48.                 ELSE
  49.                     Current = 1
  50.                 END IF
  51.             END IF
  52.  
  53.             IF StartPosition < LBOUND(vf) THEN StartPosition = LBOUND(vf)
  54.             EndPosition = StartPosition + 22
  55.  
  56.             IF EndPosition > i THEN EndPosition = i
  57.             IF EndPosition < 22 THEN EndPosition = 22
  58.             IF EndPosition > UBOUND(vf) THEN EndPosition = UBOUND(vf)
  59.             IF StartPosition + Current >= UBOUND(vf) THEN Current = UBOUND(vf) - StartPosition
  60.  
  61.             CLS
  62.             FOR Content = StartPosition TO EndPosition
  63.                 LOCATE Content - StartPosition + 1
  64.                 IF Current = Content - StartPosition + 1 THEN COLOR 1, 15 ELSE COLOR 15, 14: cur = Current + StartPosition - 1
  65.                 D$ = VF(Content) + SPACE$(_WIDTH - LEN(VF(Content)))
  66.                 PRINT D$
  67.             NEXT
  68.             _LIMIT 150
  69.         LOOP
  70.         ReadFile = VF(cur)
  71.         ERASE VF
  72.     END IF
  73.  
  74.  
  75.  
  76.  
« Last Edit: May 13, 2020, 01:54:09 pm by Petr »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: on key(11)
« Reply #9 on: May 14, 2020, 06:34:22 am »
Hi Theo
it seems that you like very much spaghetti code!
 But are spaghetti  with tomato souce and meatballs? Or do you like pesto on spaghetti? :-)
I think that if you are used to create subprograms by GOSUB RETURN, easily you can change that to FUNCTION END FUNCTION learning how safe is to have local variables and in the same time having the possibility to SHARED the common or global variables.

Good Luck on coding
Programming isn't difficult, only it's  consuming time and coffee