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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New line after reading text file

Status
Not open for further replies.

katididdy

Technical User
Joined
Mar 13, 2006
Messages
70
Location
US
I am trying to read a text file into a text box. When the file is displayed, all data is on one line. How do I get the next line of data to go to the next line?

Example:

employees.ini

Lastname1, FirstName1
Lastname2, FirstName2
Lastname3, FirstName3

The output is:

Lastname1, Firstname1Lastname2, FirstName2Lastname3, FirstName3

my code:

Private Sub Form_Load()
Dim nFileNum As String

' Get a free file number
nFileNum = FreeFile

' Open Employees.ini
Open App.path & "\employees.ini" For Input As nFileNum

' Read the contents of the file into TextBox1
Textbox1.Text = Input(LOF(nFileNum), nFileNum)

Do While Not EOF(nFileNum) ' Loop until end of file.
Line Input #FreeFile, nFileNum ' Read line into variable.

Loop

' Close the file
Close nFileNum

End Sub

Any help would be greatly appreciated!
 
Add a VBCrLf to the textbox before you loop for the next line

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Thank you for your response!

I get an error message that states:

Invalid use of property.

no matter where I put it.
 
A textbox has a multiline property that defaults to False. You'll need to change this to True.

[tt][blue]TextBox1.Multiline = True[/blue][/tt]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you so much! That did it!
 
Yesterday I put up this post and was able to get my problem resolved. Now I have one similar... I need to take the same text file and put it into a list box. I am a newbie to VB, and am having trouble. Can anyone point me in the right direction?
 
What have you tried so far?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I've tried using form_load and changing Textbox1 to List1 (didn't work). I've tried put the text file into an array then writing it to the listbox. I put the path in the properties section of data source. I thought it would be similar to a text box... I think I was wrong! I'm currently googling for help, but either I'm missing something, or I can't find just what I'm looking for.
 
>> I've tried put the text file into an array then writing it to the listbox.

This is the approach I would take. Once the file is in an array, you will need to loop through the array and use the ListBox's .AddItem function.

Try this. If you run in to problems, post back with some code and we will help you through it.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
started 17 threads, posted 22 replies




katididdy,

I notice that over the past 2 years, you have started 17 threads, posted 22 replies and have received many good tips related to your stated needs. Yet, you have NEVER responded, to
[blue]
Thank Tek-Tip Contributor
for this valuable post!
[/blue].

The little purple Stars accomplish several important things.

First, it gives positive feedback to contributors, that their posts have been helpful.

Second, it identifies threads as containing helpful posts, so that other members can benefit.

And third, it identifies the original poster (that's YOU, BTW), as a grateful member, that not only receives, but is willing to give tokens of thanks.

Skip,

[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue]
 
Skip,

You're right! It wasn't an intentional wrong that I didn't do that, but thank-you for calling me on it. I will do that!
 


:-)

Skip,

[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top