Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The program only wants to run once . . .
#1
Sad 
The program only ever works once. Then one have to delete the exe file, otherwise it will always just show "unknown". Even deleting the program and using a different name didn't help. Does anyone know what could be wrong? Thanks!

I think I've had a similar case before, but I can't remember how I solved the problem.

Code: (Select All)

'Codenummer der gedrueckten Taste ermitteln - 30. Juli 2024

Option _Explicit

Dim As Integer x

Print "Taste"
_Delay 2

x = _KeyHit
If x = 32 Then
  Print "Leertaste "; x
ElseIf x = 27 Then
  Print "Esc-Taste "; x
Else
  Print "Unbekannt"
End If

End

[Image: Funktioniert-nur-einmal.jpg]
Reply
#2
Don't you need a loop to keep it going?
Reply
#3
Could you give a bit more of an explanation of what goes wrong? The screenshot looks like it shows two functional runs of the program and neither of them hit the "Unbekannt" case.
Reply
#4
Works fine for me
I run hit escape and 27 comes up
I run again hit spacebar and 32 comes up
I run again hit a and get some Unbekannt word comes up.

What is wrong with any of that? no rhyming?
b = b + ...
Reply
#5
(07-30-2024, 06:57 PM)DSMan195276 Wrote: Could you give a bit more of an explanation of what goes wrong? The screenshot looks like it shows two functional runs of the program and neither of them hit the "Unbekannt" case.
When I reloaded and started the program, it worked, despite the old exe file. When I started it again, see screenshot.
At first it wasn't saved, but I also deleted the "untitled.exe". It is normally that the exe-file is saved in the same directory as the source file.
I am now sure that I have had this problem before.

[Image: Funktioniert-Nur-Einmal2024-07-30-223400.jpg]
Reply
#6
(07-30-2024, 08:46 PM)Kernelpanic Wrote: When I reloaded and started the program, it worked, despite the old exe file. When I started it again, see screenshot.
At first it wasn't saved, but I also deleted the "untitled.exe". It is normally that the exe-file is saved in the same directory as the source file.
I am now sure that I have had this problem before.

[Image: Funktioniert-Nur-Einmal2024-07-30-223400.jpg]
What about that screenshot shows it running incorrectly? That's what I'm missing, it looks like it ran just fine and hit the case where `_KeyHit` returned zero

Is the problem the "Untitled" in the title?
Reply
#7
Quote:What about that screenshot shows it running incorrectly? That's what I'm missing, it looks like it ran just fine and hit the case where `_KeyHit` returned zero

Is the problem the "Untitled" in the title?
Again:
I start the program, press the space bar, and it is displayed correctly. I start the program again, press the space bar again, and it displays "unknown". The same thing happens with "ESC".
After deleting the exe file, it works again, but only once. Then the game repeats itself. I just tried it again.
Reply
#8
Sylvester, err Kernelpanic is right, the program doesn't behave as one would expect
Reply
#9
The _DELAY 2 isn't a very reliable way to try and get a keypress into the keyboard buffer.   Start up times vary, so if the screen is initialing and you hit that space bar, it may not register it.  

Instead of just k = _KEYHIT, trap for a key event and then move on.

DO
    k = _KEYHIT
LOOP UNTIL k


If you want to include it in a timer, then try something like:

t# = TIMER + 2.0  <-- 2 seconds
DO 
   k = _KEYHIT
LOOP UNTIL k OR (TIMER > t#)

Is this a Linux only issue?  I can't seem to reproduce it at all, on my Win 11 machine.
Reply
#10
Steve, I ran it on Win 11 and it shows the problem. have not tried it on Linux
Reply




Users browsing this thread: 9 Guest(s)