|
-
Jul 28th, 2011, 08:53 AM
#1
Thread Starter
New Member
[Help] Reading and Sorting Text from a .txt
Okay so I am very new to visual basic I am currently using VB 2010 I know that this is not the correct forum but I figured it was the closest to it since there is no VB 2010.
Anyways I am making a program for my Dad's company that can keep track of inventory so I need to store the info in a .txt and load it up etc. I currently am using a stream writer to write to the text and I got that down pat I am just having troubles loading it back up and putting the info in specific text boxes aka sorting or parsing? the information. I have looked at several tutorials and the problem is that I just simply don't know what I am looking at I've been tinkering with it for a couple hours now with no luck so I hope you guys could help me out .
Here is my current code. It is kind of useless because I have tried so many methods I thought maybe I could use a ReadAll function have it go to a string and parse from there hoping it would have been easier but it has not worked out for me so far.
Code:
Imports System.IO
Public Class FormPartList
Dim fileReader As System.IO.StreamReader
Dim Path As String = "c:\testfolder1\test.txt"
Dim StrStorage As String
Dim StrTest As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If File.Exists(Path) Then
Using tr As TextReader = New StreamReader(Path)
StrStorage = tr.ReadToEnd()
End Using
End If
TextBox1.Text = StrStorage
End Sub
End Class
This was just for testing purposes to see if I could get the reading to go the current code does read the text file and TextBox1.text displays all of the information in the text file (test.txt)
Code:
***NEW ITEM**1
254-2
Drawing Number: 254-2
Part Name: Mikes Part
Material: Aluminum
Finish: Brushed
Price: 50.00
Invoice: 323
Shipping: 654-256
Quantity: 80
Purchase Order: 956
^This above is just the output in test.txt and what will eventually need to get sorted into respective text/list boxes
Thank you in advance I'm hoping someone could help me out here
-
Jul 28th, 2011, 08:56 AM
#2
Re: [Help] Reading and Sorting Text from a .txt
Welcome to VBForums 
Thread moved from the 'VB6 and Earlier' forum to the 'VB.Net' (VB2002 and later) forum
-
Jul 28th, 2011, 09:29 AM
#3
Thread Starter
New Member
Re: [Help] Reading and Sorting Text from a .txt
haha ty for the moving stupid question lol is VB 2010 VB.net??
-
Jul 28th, 2011, 09:51 AM
#4
Re: [Help] Reading and Sorting Text from a .txt
Yes, as implied by my post and the forum description, VB 2002 and later (which includes VB 2010) are all VB.Net
-
Jul 28th, 2011, 02:50 PM
#5
Re: [Help] Reading and Sorting Text from a .txt
try this. it reads your textfile, discards the first 2 lines (let me know if that's wrong), + splits the next 9 lines on the ": " + puts the second part of those lines in individual textboxes:
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lines() As String = IO.File.ReadAllLines("c:\testfolder1\test.txt")
Dim textboxes() As TextBox = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, TextBox7, TextBox8, TextBox9}
Array.ForEach(textboxes, Sub(tb) tb.Text = lines(2 + Array.IndexOf(textboxes, tb)).Split(New String() {": "}, StringSplitOptions.None)(1))
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 28th, 2011, 03:18 PM
#6
Re: [Help] Reading and Sorting Text from a .txt
If you are to use a text file as a way of storing tabular data, you at least should pick the appropriate format such as csv or tab delimited where each text line represents a record and the commas or the tabs are field separators.
However, for a program to be used in real business (your Dad's company), I strongly advice the use of a database.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
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
|