02-13-2026, 06:07 AM
Thank you everyone. I don’t have the ability to rewrite complex code — I saw the InputBox implementation on the QB64.com forum, and the code was too complicated for me.
Recently, I had some time to revisit the issue of garbled characters returned by InputBox$, and I discovered there is still a pattern. My guess is that QB64 encounters issues when parsing double-byte Chinese characters during encoding conversion. The specific pattern is as follows:
When X ≥ 192 (0xC0):
First byte = 195, second byte = 128 + (X - 192)
When 128 ≤ X < 192:
First byte = 194, second byte = X
Reverse conversion (fix function):
If the first byte = 195:
Original GBK byte = 192 + (second byte - 128)
If the first byte = 194:
Original GBK byte = second byte
Since the mapping is this simple, handling it becomes straightforward.
This code probably won’t be testable or useful for our Latin-alphabet friends, but I’m posting it here for anyone who might need it.
Additionally, I believe this is a bug in the function itself. I hope the development team can fix it and improve this otherwise very useful built-in function.
Recently, I had some time to revisit the issue of garbled characters returned by InputBox$, and I discovered there is still a pattern. My guess is that QB64 encounters issues when parsing double-byte Chinese characters during encoding conversion. The specific pattern is as follows:
When X ≥ 192 (0xC0):
First byte = 195, second byte = 128 + (X - 192)
When 128 ≤ X < 192:
First byte = 194, second byte = X
Reverse conversion (fix function):
If the first byte = 195:
Original GBK byte = 192 + (second byte - 128)
If the first byte = 194:
Original GBK byte = second byte
Since the mapping is this simple, handling it becomes straightforward.
Code: (Select All)
Function FixByte% (b1 As _Unsigned _Byte, b2 As _Unsigned _Byte)
If b1 = 195 Then FixByte = 192 + (b2 - 128) ' C3 prefix
If b1 = 194 Then FixByte = b2 ' C2 prefix
End Function
Code: (Select All)
$Console:Only
Function FixByte% (b1 As _Unsigned _Byte, b2 As _Unsigned _Byte)
If b1 = 195 Then FixByte = 192 + (b2 - 128) ' C3前缀
If b1 = 194 Then FixByte = b2 ' C2前缀
End Function
Print
Dim As String a, a1, fixa: a1 = "中"
Print "a and a1 are the same Chinese character-->'中'"
Print "a1 ascii code: "; Asc(a1, 1); " "; Asc(a1, 2)
Print "a2(Inputbox) ASCII code:";
a = _InputBox$("", "input", "中")
For i = 1 To 4
b = Asc(a, i)
Print b; " ";
Next i
Print: Print
'now fix it
Dim As _Unsigned _Byte b1, b2
Dim fixtmp As Integer
Dim As String fixchr: fixchr = ""
Print "Now,fix it."
Print "Process two bytes at a time, then concatenate them to restore."
Print "AFter fix ASCII code: ";
For i = 1 To 4 Step 2
b1 = Asc(a, i)
b2 = Asc(a, i + 1)
fixtmp = FixByte(b1, b2)
Print fixtmp; " ";
fixchr = fixchr + Chr$(fixtmp)
Next
Print fixchr
Sleep
End
The example below is just a simple demonstration — it takes a straightforward approach. In practice, more checks and handling may be needed.This code probably won’t be testable or useful for our Latin-alphabet friends, but I’m posting it here for anyone who might need it.
Additionally, I believe this is a bug in the function itself. I hope the development team can fix it and improve this otherwise very useful built-in function.

