Does it REALLY need to be an array?
Would a List of classes or List of KeyValuePairs work?
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
I know "array" sounds easier to use, but I find they require more management than the collection classes.
I know some of these other things look hard to use at first, but if you think about it: without them, you're doing all of the work they will do for you.
I would start out with something like a List of Key/Value pairs.
The Key (user name) is on the left and the Value (path) is on the right.
...and store those in a list. My list would be named like this:
Dim lst_kvp_s2sNamePath As New List(Of KeyValuePair(Of String, String))
I would then
1) Open the text file as a StreamReader
2) Loop through the file with TWO ReadLine calls per pass (one for name, one for the path)
3) Simultaneously add the key and value to the key/value pair and to the list with:
lst_kvp_s2sNamePath.Add(New KeyValuePair(Of String, String)(strName, strPath))
If later you need to see the contents of the list, you can loop through it with a For Each
Let me know if that's confusing.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
If the Name-ID things are guaranteed to be unique, you can use a Dictionary(String, String).
That might make it less cryptic.
I used the KVP because it does not require the individual keys to be unique.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
.see if this helps.
Imports System.IO
Public Class Form1
Private myFile As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\test.txt"
Private arFileLines() As String = Nothing
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
myCoolSub()
End Sub
Private Sub myCoolSub()
If File.Exists(myFile) Then
arFileLines = File.ReadAllLines(myFile)
For i As Integer = 0 To arFileLines.Length - 1 Step +2 '// loop thru file.lines and skip reading every other line.
MsgBox(arFileLines(i) & vbNewLine & arFileLines(i + 1))
Next
End If
End Sub
End Class
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384