Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
INKEY$ doesn't work with fixed length strings
#8
(07-29-2024, 06:12 PM)Pete Wrote:
(07-28-2024, 04:07 PM)SMcNeill Wrote: Works as expected.  Try this:

...

The issue is you're printing it in an loop.  You press "A", it pops up on the screen for a poop, and then the loop just keeps repeating, and it's replaced almost instantly by nothing as it waits for the next keypress to poop up the next key being processed.
Wow, missing out on that porta-potty contract is really eating at you!

Pete Big Grin 

- I'm in with the INKEY$ crowd!

EDIT: @justsomeguy

I don't use a dim as string approach with INKEY$, I noticed this approach makes a null string as CHR$(32) + CHR$(32). That will be problematic if you intend to trap a spacebar press.

Code: (Select All)
Type tt
    ' Use 2 bytes to capture 2 byte combinations
    'k AS STRING ' Works
    k As String * 2 ' Does Not work
End Type

Dim As tt t

' Note you cannot detect a spacebar press with this 'Dim as String' approach.
Do
    t.k = InKey$
    If Len(LTrim$(t.k)) Then
        Locate 1, 1
        Print "k:"; t.k, Asc(Mid$(t.k, 1, 1)), Asc(Mid$(t.k, 2, 1)); "  "; ' Cover up larger output strings.
    End If
Loop
You make a good point. I wonder why this is the way it works. It would make more sense to be filled with NULLs than spaces.

It would be also nice, that we have new LEN() function that returns the actual length of the string.
Reply


Messages In This Thread
RE: INKEY$ doesn't work with fixed length strings - by justsomeguy - 07-30-2024, 03:18 PM



Users browsing this thread: 6 Guest(s)