Turning List into array
Turning List into array
Turning List into array
Turning List into array
Turning List into array
Turning List into array Turning List into array Turning List into array Turning List into array Turning List into array Turning List into array Turning List into array Turning List into array
Turning List into array Turning List into array
Turning List into array
Go Back  Xtreme Visual Basic Talk > > > Turning List into array


Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2009, 09:03 AM
-Cluster- -Cluster- is offline
Newcomer
 
Join Date: Feb 2009
Posts: 7
Default Turning List into array


Hi i have a simple list Format

Thing1
Thing2
Thing3

Its extracted from a text document and put in a multi line textbox in the same format. What I want to do is read each line and put it in an array, however i couldn't find code to read line by line, so I have a series of questions

1. What code do I need to put in an If statement so if it is a return (i.e. the next line) Then it runs

2. Is there a simple way to read line by line in multi textboxs so I don't need to do question 1
Reply With Quote
  #2  
Old 02-01-2009, 09:23 AM
dbasnett's Avatar
dbasnett dbasnett is offline
Junior Contributor
 
Join Date: May 2005
Posts: 299
Default

Code:
        Dim testTB As New TextBox
        For x As Integer = 1 To 10
            testTB.Text &= "Line" & x.ToString & Environment.NewLine
        Next
        '
        Dim s() As String
        s = testTB.Lines
        'the last entry in s will be empty because of the last NewLine
        Array.Resize(s, s.Length - 1)
Reply With Quote
  #3  
Old 02-01-2009, 09:35 AM
-Cluster- -Cluster- is offline
Newcomer
 
Join Date: Feb 2009
Posts: 7
Default

Thanks that is what i needed This is what i used:

Code:
        
'Sets Words in to an array
        For Cick As Integer = 1 To 10
            main.Words.Text &= "Line" & X.ToString & Environment.NewLine
        Next

        Dim List() As String
        List = main.Words.Lines

        'the last entry in line will be empty because of the last NewLine
        Array.Resize(List, List.Length - 1)
One more thing though is i want to do instead of for cick as integer = 1 to 10 i want to do 1 to (however many lines there are)

Also i have realized my text extraction from the text document is putting loads of this at the end that aren't in the file

"LineC:\Users\Vaio\Desktop\wordlist\wordlist.txt"

, is this the right way about it

Where X is the file name including pathway
Code:
        'Read from Text File
        Dim FileToRead As String
        FileToRead = My.Computer.FileSystem.ReadAllText(X, System.Text.Encoding.ASCII)

        'Sets Words in to textbox
        main.Words.Text = FileToRead

Last edited by -Cluster-; 02-01-2009 at 10:29 AM.
Reply With Quote
  #4  
Old 02-01-2009, 12:15 PM
user name user name is offline
Junior Contributor
 
Join Date: Sep 2004
Posts: 264
Default

Personally, if i wanted a list of each line in the text document and show the text in a textbox i would use a List(Of String) to readalllines from the document then load the textbox from the list.
Code:
Private List As New List(Of String)




List.AddRange(IO.File.ReadAllLines("X"))   'X is the path

main.Words.Lines = List.ToArray
Reply With Quote
  #5  
Old 02-01-2009, 04:50 PM
killian35 killian35 is offline
Freshman
 
Join Date: Mar 2004
Posts: 49
Default

You don't need the List(Of String) for this implementation. That is simply an extra step. Just assign the lines directly to the TextBox.
Code:
main.Words.Lines = IO.File.ReadAllLines(path)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Turning List into array
Turning List into array
Turning List into array Turning List into array
Turning List into array
Turning List into array
Turning List into array Turning List into array Turning List into array Turning List into array Turning List into array Turning List into array Turning List into array
Turning List into array
Turning List into array
 
Turning List into array
Turning List into array
 
-->