Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i need a help on reading a specific data in large file.

i have text file containing values such as product id= id89et place = india etc without any comma separated.
i need to read this file and displaying all values in a every text box.

please help me how to read this file, i am newly in vb.net programing so i haven't any idea to perform this task.
please give me some starting point of coding for it.

thanks in advance.
Posted
Comments
Richard C Bishop 5-Mar-13 14:29pm    
What type of file is it? Excel, .csv, .txt?
Vishal Makwana 5-Mar-13 14:37pm    
simple text file having extension .0fl , but i can open file in notepad.

If you have no unique separators and no fixed columns, then you are pretty limited in how you can do this.
for example, your data does not make it clear that your line consists of two values:
product id= id89et
place = india
I assume it does, and that any whitespace terminates the value, but with only two entries on a single line and the comment "etc" it is a dangerous assumption.

I would start with a regular expression: Read all the file into a string, try something like this:
VB
Public Dim regex As Regex = New Regex( _
      "(?<Key>.+?)=(?<Value>.+?)\s", _
    RegexOptions.IgnoreCase _
    Or RegexOptions.Multiline _
    Or RegexOptions.Singleline _
    Or RegexOptions.CultureInvariant _
    Or RegexOptions.IgnorePatternWhitespace _
    Or RegexOptions.Compiled _
    )


Dim ms As MatchCollection = regex.Matches(InputText)
For Each m As Match In ms
    Console.WriteLine(m.Groups("Key").Value)
    Console.WriteLine(m.Groups("Value").Value)
Next
 
Share this answer
 
Comments
Maciej Los 5-Mar-13 15:08pm    
+5!
Vishal Makwana 6-Mar-13 14:23pm    
Maciej Los:-

it doesn't work.
give any other idea for it that i can understand and implement it
OriginalGriff 6-Mar-13 14:30pm    
"it doesn't work" is not exactly helpful - if you don't tell us what it does do, what it should do, and what it does wrong then we have no info to base a new solution on. So what happens that shouldn't, or doesn't happen that should? Does it do anything right? If so, what? Or could you not work out what to do with the code?
phil.o 22-Mar-13 13:26pm    
5'd, as with what was given it was quite hard to guess how to handle the mess. Regular expression seemed to best the best way, at first glance.
I found solution my self..

first of all i need a index of my file values suppose product id =id09876543 location =india then index values of id09876543 is " 12 to 23 " then i will pass 12 and 23 in function calling.

1) make a user define function called "read_value" pass the 2 argument in it in integer form and make function as string i.e. it will return value in string format.

2) call that function in your specific place where you want the answer.

like this.

1)

Public Function read_value(ByVal strat As Integer, ByVal end1 As Integer) As String

Dim fs As FileStream = New FileStream(f_name, FileMode.Open, FileAccess.Read)

Dim n As Integer = 0
Dim s As String = Nothing
Dim i As Integer = 0
Dim l As Long = strat
fs.Seek(l, SeekOrigin.Begin)
'Seek(strat)
For i = strat To end1
n = fs.ReadByte()
s = s + Convert.ToChar(n)
Next
Return s
End Function

2)

Dim ofd1 As New OpenFileDialog ' Dim file_name As String Try If ofd1.ShowDialog = Windows.Forms.DialogResult.OK Then f_name = ofd1.FileName

product_id_txt.Text = read_value(12, 23)
location_txt.Text = read_value(34, 50)
form.Show()
End If
Catch ex As Exception
MessageBox.Show("File Not Found")
End Try

Output of this code is
id09876543 <---- this is my text box value

this is done..
 
Share this answer
 
Comments
phil.o 22-Mar-13 13:26pm    
I think a regular expression will handle things smoother here, but it's hard to guess as you did not mention whether your data is of fixed width or not.
Vishal Makwana 1-Apr-13 12:30pm    
yes in my case the data is of fixed width.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900