Possible bug? Unable to enter a comma in response to INPUT
#1
In QB64pe 0.8.2 take a look at this code:

Code: (Select All)
a$ = "This is a string, with a comma"
Input b$

Print a$
Print b$

Notice that the first line simply set a string and that the string contains a comma.
The second line is asking for input from a user. Start typing in a string of characters, and somewhere along the line, try to type a comma. The comma will not be accepted.

When it gets to the print statements, it prints the string of text that includes a comma, so clearly a comma is a valid character in a string. Since a comma is a valid character, an INPUT should allow a user to input a comma as part of the string.
Reply
#2
This behavior is correct, it has to do with how
Input
allows entering multiple variables at once (with their values separated by a comma). Because of that, when using
Input
with a string on its own you cannot include a comma in the value. You should use
Line Input
instead, which basically works exactly like you want - it reads an entire line of input text into a single string, with no limitations on commas or etc. being in it.

There is a note about this behavior on the Wiki, it goes into a bit more detail:

https://qb64phoenix.com/qb64wiki/index.php/INPUT
Reply
#3
Thanks, much appreciated
Reply
#4
Use Line Input when you want to allow commas. 

BTW Input allows multiple Input because comma!

Code: (Select All)
Input "Give me a number comma another "; a, b
Print a, b

   
b = b + ...
Reply
#5
If commas are needed, use something like this:

Locate 10, 1: b$ = "": Print "Your texte here, (with comma also) : ";
Text: GoSub saiscar: If z$ <> Chr$(13) Then Print z$;: b$ = b$ + z$: GoTo Text
Print: Print: Color 0, 7: Print b$: Color 7, 0
Sleep: End
saiscar: z$ = InKey$: If z$ <> "" Then GoTo saiscar
Sais1: z$ = InKey$: If z$ = "" Then GoTo Sais1
Return
Why not yes ?
Reply




Users browsing this thread: 1 Guest(s)