By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,456 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

reading from a text file problem

P: n/a
today I tackled, for the first time, opening and reading from a text
file.

Following the example on the MSDN and declared a variable, strline as a
string and objstreamreader as a streamreader.

Basically I read in a line of a text file - this works fine.
I then read in another line. This works fine
However, the third time round I read character by character, until I
get to to the 40th character on the line, because this is the position
of some information that is a variable that I need. The problem is that
when using the read command (strline = objstreamreader.read) each
character is being given as a number (for example, when a space is read
in the string shows the number "32"). When I get to the correct
character I should get the string "1", instead I'm getting something
else. (A different number, but it's definately a translation of 1, not
the wrong character because all other characters on the line are
letters from a to z).

does anyone know why this happens and how I can re-translate the
number/code back into an alphanumeric version?

thanks,

Steve

Feb 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
SteMc wrote:
today I tackled, for the first time, opening and reading from a text
file.

Following the example on the MSDN and declared a variable, strline as a
string and objstreamreader as a streamreader.

Basically I read in a line of a text file - this works fine.
I then read in another line. This works fine
However, the third time round I read character by character, until I
get to to the 40th character on the line, because this is the position
of some information that is a variable that I need. The problem is that
when using the read command (strline = objstreamreader.read) each
character is being given as a number (for example, when a space is read
in the string shows the number "32"). When I get to the correct
character I should get the string "1", instead I'm getting something
else. (A different number, but it's definately a translation of 1, not
the wrong character because all other characters on the line are
letters from a to z).

does anyone know why this happens and how I can re-translate the
number/code back into an alphanumeric version?

thanks,

Steve


When you read character by character you are getting the ASCII
representation of the character. If you do Chr(strline) on the one you
expect as "1" you will get your "1".

You may want to just read in the entire line and then do a substring on it.

strline = objstreamreader.readline
debug.writeline("My 40th Char is: " & strline.substring(39,1))

Chris
Feb 19 '06 #2

P: n/a
Ste,

The streamreader reads forever into a String (It can be in another format on
disk and than you can use the encoding). A String is in .Net forever in
Unicode format.

To get the value for that you can use the convert to Ascii which was in past
Asc and because that the characterset is now more wide better to use the
newer AscW("2"). The last instruction will give you "32".

In the otherway to get from a Unicode a Charachter it is ChrW(32) which will
give a 2.

I hope this helps,

Cor
Feb 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.