Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:37 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : line input command unexpected behaviour

Author Message
crez

Senior Member

Joined: 24/10/2012
Location: Australia
Posts: 152
Posted: 08:49pm 04 Jun 2021
Copy link to clipboard 
Print this post

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: Australia
Posts: 3292
Posted: 03:24am 05 Jun 2021
Copy link to clipboard 
Print this post

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: Australia
Posts: 152
Posted: 03:41am 05 Jun 2021
Copy link to clipboard 
Print this post

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: Australia
Posts: 2640
Posted: 04:12am 05 Jun 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4311
Posted: 06:13am 05 Jun 2021
Copy link to clipboard 
Print this post

  Geoffg said  ... handling the variations in terminating the line (ie, CR, LF, CR/LF, etc).


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: Australia
Posts: 3292
Posted: 08:49am 05 Jun 2021
Copy link to clipboard 
Print this post

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
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025