Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't read a text file containing a value with a comma

Status
Not open for further replies.

pbuddy2007

Technical User
Feb 9, 2008
17
0
0
CA
I'm saving in a text file the value : 100,000 using :

FileNum = FreeFile
Open App.Path & "\temp\file.jfl" For Output As FileNum
Print #FileNum, Text1.Text
Close FileNum

and I'm reading the same file using :
FileNum = FreeFile
Open App.Path & "\temp\file.jfl" For Input As #FileNum
Input #FileNum, tx1
Close #FileNum
Text1.Text = tx1


The problem is that text1.text only print : 100 but the content of the file itself is really 100,000 .

The routine I"m using to read the data stops at the comma.

How can I resolve this issue so that text1.text will print 100,000
 
That is the correct behavior for the Input function. It really is designed for reading comma delimited files (where each data element is separated by a comma).

You can easily fix this by using a different function. Line Input, like this...

Code:
FileNum = FreeFile
Open App.Path & "\temp\file.jfl" For Input As #FileNum
[!]Line[/!] Input #FileNum, tx1
Close #FileNum
Text1.Text = tx1

Line input will read the entire line (up to, but not including a carriage return-line feed sequence).



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
gmmastros you shall now be declared the king of all kings...

this <<simple>> problem has been driving me nuts for the past 2 hours
 
That title is taken. Can I have another?

Ideas...

Seriously, though... I'm glad I could help.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
And, one should point out, that the final line of the input file must be terminated with a CRLF, otherwise it will not be read at all. This won't be a problem if you're only reading the file you produced in your example (Print always adds the correct endline) but the lack of a CRLF often bites people who try to read files produced by a text editor.
 
>That title is taken.

Given ain't the same as taken... :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top