Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2010 > Visual Basic 2010 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2010 General Discussion For any discussions about Visual Basic 2010 topics which aren't related to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 3rd, 2012, 07:51 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Location: Crawley
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default VB 2010 text file to listbox

hi, i want to open a text file into a listbox, this i have managed. however i need to take out the first line of the text file and put that into a label once i have opened the text file. any help please
Reply With Quote
  #2 (permalink)  
Old September 3rd, 2012, 09:19 AM
Authorized User
Points: 257, Level: 5
Points: 257, Level: 5 Points: 257, Level: 5 Points: 257, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Location: Healing, UK
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Hi,

Please can you post the first few lines of your file so that I can see what you are trying to achieve. - (You cannot load files in this forum so please wrap the first few lines of the file in quote tags to keep the formatting) - In essence, this should be easily achievable by searching for the first Carriage Return, which then gets placed in the label and then the rest goes in the Listbox.

Cheers

Ian.
Reply With Quote
  #3 (permalink)  
Old September 3rd, 2012, 09:24 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Location: Crawley
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

VB10
01/06/2010,140
02/06/2010,255
03/06/2010,252
04/06/2010,314
07/06/2010,28
08/06/2010,309
09/06/2010,69
10/06/2010,222
11/06/2010,81
14/06/2010,236
15/06/2010,171
16/06/2010,217
17/06/2010,285
18/06/2010,82
21/06/2010,203


That is some of the text file... the "VB10" is what i want to extract and make that the label.
Reply With Quote
  #4 (permalink)  
Old September 3rd, 2012, 10:19 AM
Authorized User
Points: 257, Level: 5
Points: 257, Level: 5 Points: 257, Level: 5 Points: 257, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Location: Healing, UK
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Hi,

Here is an example of how you can achieve what you are trying to do:-

1) Add a Label and a Listbox to a form.
2) Copy the code below to the form load event ensuring you replace the test.txt filename with your own file location and name.

Code:
    
'read the file
    Dim fileContents As String
    fileContents = My.Computer.FileSystem.ReadAllText("d:\temp\test.txt")
    'strip out the first line of the file using indexof to find the first CR/LF and then apply to the label
    Label1.Text = fileContents.Substring(0, fileContents.IndexOf(vbCrLf))
    'strip out the first line of the file, compensating for the space needed for CR/LF and then apply to the listbox
    fileContents = fileContents.Substring(fileContents.IndexOf(vbCrLf) + vbCrLf.Length, fileContents.Length - fileContents.IndexOf(vbCrLf) - vbCrLf.Length)
    ListBox1.Items.Add(fileContents)
I notice that the subsequent lines in the file have multiple fields? So a question would be:- Is a list box the right control for what you want to do depending on what you are trying to show?

Hope this helps.

Kind regards,

Ian
Reply With Quote
The Following User Says Thank You to Ian Ryder For This Useful Post:
botes82 (September 3rd, 2012)
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vb.Net 2003 : How to Open and Read an XML File to TEXT File. Lennie VS.NET 2002/2003 0 February 12th, 2010 04:18 PM
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM
Save PDF file as text file in VB.Net kvenkatu Classic ASP Basics 0 April 7th, 2006 01:09 PM
save a PDF file as text file through VB. NET kvenkatu VB.NET 0 April 6th, 2006 12:15 PM
Save my ListBox data into text file kaifong78 VB.NET 2002/2003 Basics 0 September 14th, 2004 11:46 PM



All times are GMT -4. The time now is 02:39 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.