Reading a text file char by char. 
Author Message
 Reading a text file char by char.

Im trying to read a text file character by character
Here is some code i wrote, it inputs garbage instead of the
characters. What am i doing wrong?

Dim achar As String * 1
Dim aword As String
CommonDialog1.ShowOpen

Open CommonDialog1.FileName For Input As #1
    Do While Not EOF(1)
        Input #1, achar
        aword = aword + achar
            If achar = Chr(32) Then
        `its a word do what i will          
            End If

    Loop
Close #1



Fri, 19 Jul 2002 03:00:00 GMT  
 Reading a text file char by char.


Quote:
> Im trying to read a text file character by character
> Here is some code i wrote, it inputs garbage instead of the
> characters. What am i doing wrong?

> Dim achar As String * 1
> Dim aword As String
> CommonDialog1.ShowOpen

> Open CommonDialog1.FileName For Input As #1
>     Do While Not EOF(1)
>         Input #1, achar
>         aword = aword + achar
>             If achar = Chr(32) Then
> `its a word do what i will
>             End If

>     Loop
> Close #1

open yur file in binary mode.
and use Get like this.............

 Dim achar As String * 1
 Dim aword As String
 CommonDialog1.ShowOpen

 Open CommonDialog1.FileName For Binary As #1
     Do While Not EOF(1)
         Get #1, , achar                     'use Get and note the 2 commas
(there is an implied file postion arg)
         aword = aword & achar
             If achar = Chr(32) Then
                  Msgbox aword
                  End
             End If
     Loop
 Close #1



Fri, 19 Jul 2002 03:00:00 GMT  
 Reading a text file char by char.
soma

Use the Input function, not the Input # statement (this looks for
comma-delimited fields).

achar = Input(1, 1)

Incidentally, you shouldn't really use a file number of 1 - use the number
returned by FreeFile.

It's also a good idea to use & instead of + when handling strings.

--
Regards
{*filter*}

Remove '!no!spam!' to reply by e-mail but reply to newsgroup as well.


Quote:
> Im trying to read a text file character by character
> Here is some code i wrote, it inputs garbage instead of the
> characters. What am i doing wrong?

> Dim achar As String * 1
> Dim aword As String
> CommonDialog1.ShowOpen

> Open CommonDialog1.FileName For Input As #1
>     Do While Not EOF(1)
>         Input #1, achar
>         aword = aword + achar
>             If achar = Chr(32) Then
> `its a word do what i will
>             End If

>     Loop
> Close #1



Fri, 19 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Newbie Quest - Reading a char from a text file

2. Char by Char file input?

3. Reading DOS-text with special chars??

4. ASCII Chars -> large chars

5. char after each 2 chars in a string.

6. Getting a single char, Putting a single char.

7. REPOST: Want mask chars but not prompt chars in MaskEdBox (from Aug 22)

8. Want mask chars but not prompt chars in MaskEdBox

9. problem with char field and special ascii char

10. Help required for Unicode Chars(greek chars)

11. Search Char By Char Like MS Index Searches

12. Win API To Search Char by Char

 

 
Powered by phpBB® Forum Software