|
-
Sep 6th, 2010, 10:31 PM
#1
Thread Starter
Member
Help with reading text
Hi guys,
As the title says, I'm having some trouble with reading text and other stuff, I'll try to explain the situation as best I can.
Text File Layout:
Code:
Computer Name: COMPUTERNAM | User Name: TEST123 | Date: DD/MM/YYYY | Time: H:MM:SS AM
Okay, say you have 20 rows of the above, all with different Usernames, Times and Dates (The Computer Name field is the same for each row).
What I want this program to do is read the last 4 lines, so in this situation it would be rows 17, 18, 19 and 20. Then I need it to search each of those 4 rows for "| User Name: " and display the following 7 characters. (Username is always 7 characters.)
What I have so far:
So far I have been able to get it to open the file and display the whole text (the easiest part). The laptop name is derived from the user input.
Code:
Dim LaptopName As String = "\\path_to_shared_network_drive\" & txtInput & ".txt"
Dim TextLine As String
Dim objReader As New System.IO.StreamReader(LaptopName)
Do While objReader.Peek() <> -1
UsedBy = TextLine & objReader.ReadLine() & vbNewLine
Loop
Using the above code I am only able to retrieve the last line of the text file.
Code:
objReader.Close()
UsedBy1 = Mid$(UsedBy1, 44, 7)
imgUsedBy1.Image = Image.FromFile("\\path_to_image_drive\images\" & UsedBy1 & ".jpg"
This code works to an extent. The issue with this part is, the computer name length differs from the type of laptop, so starting at position 44 will only work for 1 kind of computer. What I need instead of starting at 44 is to make it search for " | User Name: " and displaying the following 7 characters (The same method would also be used for TIME and DATE).
If anyone could help me sort this out I'd really appreciate it. Please ask if you need any more info or anything is unclear.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|