Getting Error While Read Data
Amit kumar Yadava
81
Reputation points
Hi All, I am getting error while reading a data from notepad. I hope someone can help me. My File is DummyKh.txt My code are
Option Strict On
Option Explicit On
Public Class Form1
Dim lines As New List(Of String)
Dim linestoremove As New List(Of String)
Dim dt As New DataTable
Private Sub FillData()
lines = IO.File.ReadAllLines(LabelFile.Text).ToList
For i As Integer = 0 To 1000 ' NOT a valid idea !!!!
Dim f1 As String = FindData("Village Code / Name(6/7)")
Dim f2 As String = FindData("Grower Code / Name(8)")
Dim f3 As String = FindData("Adhar Number(14)")
Dim f4 As String = FindData("Mobile Number(13)")
If f1.Trim.Length > 0 Then
dt.Rows.Add(f1, f2, f3, f4)
dt.AcceptChanges()
For Each line As String In linestoremove
lines.Remove(line)
Next
End If
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With dt
.Columns.Add("Village", GetType(String))
.Columns.Add("Grower", GetType(String))
.Columns.Add("Adhar", GetType(String))
.Columns.Add("Mobile", GetType(String))
End With
DataGridView1.DataSource = dt
End Sub
Function FindData(s As String) As String
Dim fld As String = String.Empty
For Each line As String In lines
Dim st As Integer = line.IndexOf(s)
If st > -1 Then
Dim num As String = String.Empty
For i As Integer = st + s.Length To line.Length - 1
Dim ch As Char = line(i)
If IsNumeric(ch) Then
num &= ch
ElseIf IsNumeric(num) Then
linestoremove.Add(line)
Return num
End If
Next
End If
Next
Return String.Empty
End Function
Dim Ofd As OpenFileDialog
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Ofd = New OpenFileDialog
If Ofd.ShowDialog = DialogResult.OK Then
LabelFile.Text = Ofd.FileName
dt.Clear()
FillData()
End If
End Sub
End Class
Developer technologies | VB
Developer technologies | VB
An object-oriented programming language developed by Microsoft that can be used in .NET.
Sign in to answer