• Welcome to Valhalla Legends Archive.
 

[VB 6] Reading from a text file problem

Started by Dark-Feanor, December 17, 2003, 10:56 PM

Previous topic - Next topic

Dark-Feanor


   Close #1
   Open (App.Path & "\Font.txt") For Input As #1
   Dim pos As Byte
   Dim array(10) as string
   pos = 0
   Do
      Input #1, array(pos)
      pos = pos + 1
   Loop Until EOF(1)

Above is a sample of the kind of reading from .txt file that I am talking about.
It seems to me that VB 6 discards all of the spaces before the first character on the line. So, if you have a line like this:
                              blah
it will read it as:
blah

For what I  am working on (text art stuff), the spaces before the first char are important, so I was woundering if anybody knows a way to get around this space discarding?  Thank you for any help you can offer.
- Feanor[xL]
clan exile
Firebot
iago: "caps lock is like cruise control for cool"

Grok

I think you want this instead:

Dim nF As Integer
Dim Fn As String
Dim L As String
Fn = "C:\Temp\Somefile.txt"
nF = FreeFile
Open Fn For Input As #nF
Do While Not EOF(nF)
   Line Input #nF, L
Loop

Dark-Feanor

Just replaced Input with Line Input and that made it work. Thanks a lot grok :P
- Feanor[xL]
clan exile
Firebot
iago: "caps lock is like cruise control for cool"

Grok

Quote from: DaRk-FeAnOr on December 18, 2003, 09:28 AM
Just replaced Input with Line Input and that made it work. Thanks a lot grok :P

Fix the other stuff too.  Make it a habit to always use FreeFile to get a file handle.  Don't assume #1 or #2, etc, is available.

Stealth

Quote from: Grok on December 18, 2003, 10:02 AM
Quote from: DaRk-FeAnOr on December 18, 2003, 09:28 AM
Just replaced Input with Line Input and that made it work. Thanks a lot grok :P

Fix the other stuff too.  Make it a habit to always use FreeFile to get a file handle.  Don't assume #1 or #2, etc, is available.

Especially if you've been using #1 or #2 elsewhere and forgot to close them.

Input is used with the Write statement to get and retrieve VB comma-separated data from a textfile, while Line Input gets a simple line of text. Input will stop reading at commas as well as the problem you have above.
- Stealth
Author of StealthBot

Adron

No, don't use #1 and #2, use #42! Much less risk of that being used already since everyone else uses #1 and #2.