Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
INKEY$ doesn't work with fixed length strings
#21
I'm all about keeping backward compatibility. So, would something as simple as ending the fixed length strings in CHR$(0) instead of CHR$(32) break many programs? If so, make it optional like metacommand? Default to legacy, add '_FIXEDSTRINGSZERO ON'

I don't mind rolling my on LEN() function, but it is difficult to tell if that space at the end of the string was put there by your code, or was part of the initialization.

Code: (Select All)
DIM a AS STRING * 8
PRINT "t.a = "; t.a
a = "01234 " ' <--- intentional space for whatever reason, but you want it have a trailing space.

As pointed out by Pete, in the case of INKEY$, k is going to get filled with 2 spaces regardless if you hit the space bar.

Code: (Select All)
DIM k AS STRING * 2
k = INKEY$
'How do you detect the space bar?


Regardless, It seems that there is little or no interest in this issue, and that I'm the oddball.  Again, I'm not dying on this hill.
Reply
#22
@justsomeguy

If I had to make a workaround in my code, I'd need to do this...

Code: (Select All)
Type tt
    ' Use 2 bytes to capture 2 byte combinations
    k As String * 2
End Type
Dim As tt t
Do
    _Limit 30
    t.k = Chr$(0) + Chr$(0) ' This line and the MID$() line below clears up the issue. Space bar can now be detected.
    Mid$(t.k, 1, 2) = InKey$
    If t.k <> Chr$(0) + Chr$(0) Then
        Print Mid$(t.k, 1, 1), Mid$(t.k, 2, 1), Asc(Mid$(t.k, 1, 1)), Asc(Mid$(t.k, 2, 1))
    End If
Loop

Pete
Reply
#23
Why not just use variable length strings and not have the worry over it?

Fixed length strings are set to a fixed length -- like a "foot long sub".
Variable length strings are set the the length of the contents -- like a "sub" can be 4 inch, 6 inch, or 12 inches.

It just seems odd, to me, to basically be asking for, "Hi.  I'd like to order a four inch, foot-long sub!"

"What?  Would you like the four inch?  Or the foot long?"

"I want the four inch, foot long sub!"

You know, I might just try that the next time I go into my local sub shop.  I'd love to see the expression on their faces!
Reply
#24
Steve, I'm sorry to hear what you call a foot long is only 4-inches, but I also hear they have pills for that problem.

My work-around method seems to work, but since I don't use fixed strings for keyboard input I won't stake my life on it. I was fun to take a poke at, but it would also be nice to find out if there is a specific and unique purpose for using a fixed length variable, or is this solely meant as a coding style, in this case using a TYPE declaration.

Oh, and thanks to Bidenflation, what you used to pay for a foot long now only buys you a 4-inch sub, and it doesn't matter how you use it, it's still too damn small!

Pete
Reply
#25
@SMcNeill
Quote:Why not just use variable length strings and not have the worry over it?
We finally come full circle. https://qb64phoenix.com/forum/showthread.php?tid=2889 and https://github.com/QB64-Phoenix-Edition/...issues/524

@Pete
(07-31-2024, 06:50 PM)Pete Wrote: @justsomeguy

If I had to make a workaround in my code, I'd need to do this...

Code: (Select All)
Type tt
    ' Use 2 bytes to capture 2 byte combinations
    k As String * 2
End Type
Dim As tt t
Do
    _Limit 30
    t.k = Chr$(0) + Chr$(0) ' This line and the MID$() line below clears up the issue. Space bar can now be detected.
    Mid$(t.k, 1, 2) = InKey$
    If t.k <> Chr$(0) + Chr$(0) Then
        Print Mid$(t.k, 1, 1), Mid$(t.k, 2, 1), Asc(Mid$(t.k, 1, 1)), Asc(Mid$(t.k, 2, 1))
    End If
Loop

Pete

Good job! It works well.
Reply
#26
@justsomeguy If you need an input with garanteed len = 1 check this out
Code: (Select All)
Do
    k$ = Input$(1)
    If k$ <> "" Then Print k$, Asc(k$), Len(k$)
    _Limit 30
Loop

It can differentiate from esc and space and enter with ASC() help and still detect but not describe 2 len arrow keys.
b = b + ...
Reply
#27
@justsomeguy

Glad you have a use for it. Yep, my mediocre solutions are always Amazing Steve! Big Grin 

Pete
Reply
#28
@bplus
Code: (Select All)
k$ = Input$(1)
That is very clever, I never knew that was an option.

There a bunch of workarounds for fixed length strings and input, but that is, what it is, a "workaround". Why do we use workarounds, because something doesn't work right, or as expected, but we are also avoiding the underlying issue.

I'm using fixed string variables in a UDT, because its a workaround for the potential crashing issues that arise from variable length string in a UDT. That will eventually get fixed, and I appreciate the time it takes for the maintainers and the developers to address all the issues and concerns, so I can be patient.
Reply
#29
I admire your faith in developers getting around to it.

Don't think I have the patience to wait, I could die tomorrow and the world would have to suffer the loss of my perspective, that would be a shame. ;-))
b = b + ...
Reply
#30
Interesting topic . . . What is it actually about?  Sad

In a record type, also called UDT, only strings with a fixed length are accepted; manual for Quick Basic 4.5. So why create a use for strings with variable length? That would no longer be compatible with QB.
Reply




Users browsing this thread: 4 Guest(s)