![]() |
Forum Index : Microcontroller and PC projects : line input command unexpected behaviour
Author | Message | ||||
crez![]() Senior Member ![]() Joined: 24/10/2012 Location: AustraliaPosts: 152 |
Open "doc.txt" For input As #1 Line Input #1,t$ For i= 1 To 10 Print Asc(Mid$(t,i,1)), Next i Close #1 Open "doc.txt" For input As #1 t=Input$(10,#1) For i= 1 To 10 Print Asc(Mid$(t,i,1)), Next i Close #1 End gives > RUN 97 32 98 32 99 32 100 32 101 32 97 9 98 9 99 9 100 9 101 9 > line input returns spaces = chr$(32) input$ returns tabs = chr$(9) which is what is in doc.txt Why? |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
LINE INPUT uses the same mechanism for getting a line as does the console and loading a program from an SD card. This includes turning tabs into spaces, setting bit 8 to zero, removing control chars and handling the variations in terminating the line (ie, CR, LF, CR/LF, etc). This was implemented many years ago and, from memory, it matches the way traditional BASICs worked (primarily Microsoft BASIC). As you pointed out INPUT$() is the way to go if you want every byte without translation. Geoff Geoff Graham - http://geoffg.net |
||||
crez![]() Senior Member ![]() Joined: 24/10/2012 Location: AustraliaPosts: 152 |
Thanks Geoff, I was tidying up a bit of code I wrote a while back that reads tab delimited fields. I couldn't remember why I hadn't used 'line input', but I do now. David |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2640 |
Same effect in a different setting - send an email containing a table with neat columns of data and it arrives messed up. Tabs turn into to spaces. |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Are you sure it handles CR without LF, i.e. Classic Mac style? I'm sure Turbo64 and I encountered one of those abominations recently and I had to write my own Line Input replacement. This was on the CMM2. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
When using INPUT or LINE INPUT MMBasic for the Micromite will work correctly with lines terminated by a CR/LF pair or a single LF. This will not affect files written by MMBasic (which normally use CR/LF) but files written with strange combinations such as a single CR or LF/CR should use INPUT$() instead. The console input will translate CR into a newline so pressing Enter on a keyboard will not cause problems. I'm not sure if this has carried into the CMM2 but I would guess that it has as it is in the core of MMBasic. I had a lot of trouble with detecting end of line (damn DOS and the rest of the world, why could you not be like UNIX?). After a lot of attempts the above was the best that I could come up with. Geoff Geoff Graham - http://geoffg.net |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |