I'm New to the VB.Net environment this is the fist program I've attempted to write. I am trying to display the first 150 records into a datagrid and then write the first 150 and the entire file into a CSV file and I'm stuck. I need to keep the column headings for future uploading. Any help would be appreciated.
Dim adparray() As String
Dim i As Integer
adparray = jobprocessing.Split(Environment.NewLine)
Dim TABLES As New DataTable
TABLES.Columns.Add("CUSTNO", GetType(System.String))
TABLES.Columns.Add("CUST FNAME", GetType(System.String))
TABLES.Columns.Add("CUST LNAME", GetType(System.String))
TABLES.Columns.Add("FULL CUST NAME", GetType(System.String))
TABLES.Columns.Add("ADDR", GetType(System.String))
TABLES.Columns.Add("CITY", GetType(System.String))
TABLES.Columns.Add("STATE", GetType(System.String))
TABLES.Columns.Add("ZIP", GetType(System.String))
TABLES.Columns.Add("LAST RO DATE", GetType(System.String))
TABLES.Columns.Add("SOLD DATE", GetType(System.String))
TABLES.Columns.Add("HOME PHONE", GetType(System.String))
TABLES.Columns.Add("SERIAL", GetType(System.String))
TABLES.Columns.Add("Keyword_Check", GetType(System.String))
TABLES.Columns.Add("NAME FAIL", GetType(System.String))
TABLES = ReadIntoTable("c:\INPUT FILES\" + IPfilename, TABLES)
Dim ROW As DataRow
Dim BADrecCount As Integer
Dim GOODRECORD As Integer = 0
Dim CUSTNO As String
Dim CUSTNAMELEN As String
Dim ADDR As String
Dim CITY As String
Dim STATE As String
Dim ZIP As String
Dim SVCDATE As String
Dim SOLDDATE As String
Dim HOMEPHONE As String
Dim CUST_FULL_NAME As String
Dim CUSTFN As String
Dim CUSTLN As String
Dim CUSTMID As String
Dim BUSINESSCOUNT As Integer
Dim keywords As String
Dim keysid As String
Dim keys As String
Dim keyarray() As String
' loads the Keyword file into array and is used to match against it.
keywords = GetFileContents("c:\keywords\keywords.txt")
keysid = keywords.Length
keys = keywords.Substring(0, keywords.IndexOf Environment.NewLine))
keyarray = keywords.Split(Environment.NewLine)
TABLES.DefaultView.Sort = "CUSTNO"
For Each n As String In adparray
ListBox1.Items.Add(n.Remove(0, 1))
n = n.Remove(0, 1)
If n.StartsWith("CUSTNO") Then
n = n.Remove(0, 6)
n = n.Trim
GOODRECORD = 0
ROW = TABLES.NewRow
ROW("CUSTNO") = n
GOODRECORD += 1
ListBox2.Items.Add(n)
ElseIf n.StartsWith("CUSTOMER NAME") Then
CUSTNAMELEN = n.Length()
n = n.Remove(0, 13)
n = n.Trim
CUSTNAMELEN = n.Length()
CUSTMID = n.IndexOf(",")
If CUSTMID >= 0 Then 'test to see if Customer name is seperated by a Comma.
CUSTLN = n.Substring(0, CUSTMID)
CUSTFN = n.Substring(CUSTMID + 1, (CUSTNAMELEN - CUSTMID - 1))
CUST_FULL_NAME = (CUSTFN & " " & CUSTLN)
ROW("FULL CUST NAME") = CUST_FULL_NAME.Trim
ListBox4.Items.Add(Split(System.Text.RegularExpressions.Regex.Replace(CUST_FULL_NAME, "\s+", Space(1))).Length - 1)
SPACECOUNT = Split(System.Text.RegularExpressions.Regex.Replace(CUST_FULL_NAME, "\s+", Space(1))).Length - 1
ListBox5.Items.Add(CUST_FULL_NAME)
ROW("CUST FNAME") = CUSTFN.Trim
ROW("CUST LNAME") = CUSTLN.Trim
GOODRECORD += 1
ListBox2.Items.Add(n)
End If
If CUSTMID < 0 Then
ROW("CUST FNAME") = n
ROW("FULL CUST NAME") = n
GOODRECORD += 1
End If
ElseIf n.StartsWith("ADDR") Then
n = n.Remove(0, 4)
n = n.Trim
ROW("ADDR") = n
GOODRECORD += 1
ListBox2.Items.Add(n)
ElseIf n.StartsWith("CITY") Then
n = n.Remove(0, 4)
n = n.Trim
ROW("CITY") = n
GOODRECORD += 1
ListBox2.Items.Add(n)
ElseIf n.StartsWith("ST") Then
n = n.Remove(0, 2)
n = n.Trim
ROW("STATE") = n
GOODRECORD += 1
ListBox2.Items.Add(n)
ElseIf n.StartsWith("ZIP") Then
n = n.Remove(0, 3)
n = n.Trim
ROW("ZIP") = n
GOODRECORD += 1
ListBox2.Items.Add(n)
ElseIf n.StartsWith("VEH-LAST-SVC-DATE") Then
Dim SHRTMO As String
Dim Day As String
Dim Year As String
Dim fullmonth As Integer = 0
Dim X As Integer
n = n.Remove(0, 17)
n = n.Trim
SHRTMO = n.Substring(2, 3)
Day = n.Substring(0, 2)
Year = n.Substring(5, 2)
Select Case SHRTMO.ToLower
Case "jan"
fullmonth = 1
Case "feb"
fullmonth = 2
Case "mar"
fullmonth = 3
Case "apr"
fullmonth = 4
Case "may"
fullmonth = 5
Case "jun"
fullmonth = 6
Case "jul"
fullmonth = 7
Case "aug"
fullmonth = 8
Case "sep"
fullmonth = 9
Case "oct"
fullmonth = 10
Case "nov"
fullmonth = 11
Case "dec"
fullmonth = 12
End Select
ROW("LAST RO DATE") = fullmonth & "/" & Day & "/" & Year
GOODRECORD += 10
ListBox3.Items.Add(ROW("LAST RO DATE"))
ListBox2.Items.Add(n)
ElseIf n.StartsWith("Sold Date") Or n.StartsWith("Sold.Date") Then
n = n.Remove(0, 9)
n = n.Trim
ROW("SOLD DATE") = n
GOODRECORD += 10
ListBox2.Items.Add(n)
ElseIf n.StartsWith("SERIAL") Then
n = n.Remove(0, 6)
n = n.Trim
ROW("SERIAL") = n
GOODRECORD += 1
ListBox2.Items.Add(n)
ElseIf n.StartsWith("HOME PHONE") Then
n = n.Remove(0, 10)
n = n.Trim
ROW("HOME PHONE") = n
GOODRECORD += 1
ListBox2.Items.Add(n)
End If
If GOODRECORD = 8 Or GOODRECORD = 18 Or GOODRECORD = 28 Then
totalrec += 1
TextBox3.Text = totalrec
TABLES.Rows.Add(ROW)
GOODRECORD = 0
Recordcounter += 1
If Recordcounter = 150 Then
DataGrid1.DataSource = TABLES.DefaultView
Application.DoEvents()
Recordcounter = 0
End If
End If
Next