PDA

View Full Version : bug in console_readline?



sandyrepope
26-02-2007, 22:53
I don't know if this is a bug in console_readline or not. If you input some characters using console_readline and try to edit it with the backspace key, then after you press enter/return the string will have the backspace in the string.

I didn't expect it to do this. Is that what it should do?

Try it with this short script:


uses "console"

dim guess as string
dim x as long

Console_write("Type something here: ")
guess = console_readline()


Console_writeline("guess is "+guess)

console_writeline("There are "+len(guess)+" characters in guess")

for x = 1 to len(guess)
console_writeline asc(mid$(guess,x,1))
next


Maybe it should do this? Type in 'apples' then hit the backspace and then 'enter'. The string will now have 7 characters instead of 5.

Thanks
Sandy

ErosOlmi
26-02-2007, 22:57
Sandy,

current functions are quite 1 to 1 wrappers of standard Win32 API console functions working with standard input. They are more suitable to manage flow of data rather than user interaction. I think we have to develop few more native thinBasic functions to be able to give you more power on reading user input.

Roberto will check it.
Ciao
Eros

ErosOlmi
26-02-2007, 23:58
Sandy,

in the meantime you can use InputBox$ (http://www.thinbasic.com/public/products/thinBasic/help/html/inputbox$.htm) function. It is not console function but can help while we are working on new functions.
Example:


dim MyVar as string

MyVar = InputBox$("Enter a number", "Title")
msgbox 0, MyVar



Eros

RobertoBianchi
27-02-2007, 18:01
Sandy,

this behaviour it's by design.
If you don't don't want deal with backspace, carriage return, and linefeed characters and let the system to handle them, you should set properly the input mode of a console's input buffer as following:


uses "console"

dim guess as string
dim x as long

Console_SetInputMode(%Console_ENABLE_PROCESSED_INPUT)

Console_write("Type something here: ")
guess = console_readline()

Console_writeline("guess is "+guess)

console_writeline("There are "+len(guess)+" characters in guess")

for x = 1 to len(guess)
console_writeline asc(mid$(guess,x,1))
next


Please note that a carriage return character is always appended to the string.

Regards,
Roberto