Hey all I have a wired issue I have a csv file with , seperated values
I have some code to read the file and put the record into an array then
into textboxes. the problem is it seems to read everyother line of the
file not everyline at first I thought it might be the code then the csv
file The csv is a mysql generated via webmin however I cant seem to
find the problem anywhere so please advise.
-- CODE--
Public Sub csv_conn()
'Opens CSV File reads contents Writes them to an Array then
Sets values to textboxes
Call save()
Dim line_num As Integer
Dim psrdCurrent As System.IO.Strea mReader
Dim psrdline As String
Dim pstrfields() As String
Dim filename As String
filename = "READ FILENAME"
psrdCurrent = New System.IO.Strea mReader(filenam e) ' OPen File
psrdline = psrdCurrent.Rea dLine()
Do Until line_num = currecord
Dim psrdfile As String
psrdfile = psrdline & CrLf
psrdline = psrdCurrent.Rea dLine()
Dim currentlinevalu e As String
currentlinevalu e = psrdCurrent.Rea dLine()
pstrfields = Split(psrdline, ",") ' Parses document into an
Array with a , seperated value.
companytxt.Text = pstrfields(1) ' Setting Text to Textboxes
Nametxt.Text = pstrfields(2)
addrtxt.Text = pstrfields(3)
citytxt.Text = pstrfields(4)
statetxt.Text = pstrfields(5)
ziptxt.Text = pstrfields(6)
countrytxt.Text = pstrfields(7)
phonetxt.Text = pstrfields(8)
faxtxt.Text = pstrfields(9)
celltxt.Text = pstrfields(10)
titletxt.Text = pstrfields(11)
assistanttxt.Te xt = pstrfields(12)
urltxt.Text = pstrfields(13)
altcontacttxt.T ext = pstrfields(14)
altphonetxt.Tex t = pstrfields(15)
altaddrtxt.Text = pstrfields(16)
altcitytxt.Text = pstrfields(17)
altstatetxt.Tex t = pstrfields(18)
altziptxt.Text = pstrfields(19)
altcountrytxt.T ext = pstrfields(20)
user1txt.Text = pstrfields(21)
user2txt.Text = pstrfields(22)
user3txt.Text = pstrfields(23)
user4txt.Text = pstrfields(24)
user5txt.Text = pstrfields(25)
user6txt.Text = pstrfields(26)
user7txt.Text = pstrfields(27)
user8txt.Text = pstrfields(28)
user9txt.Text = pstrfields(29)
user10txt.Text = pstrfields(30)
user11txt.Text = pstrfields(31)
user12txt.Text = pstrfields(32)
user13txt.Text = pstrfields(33)
user14txt.Text = pstrfields(34)
user15txt.Text = pstrfields(35)
territorytxt.Te xt = pstrfields(26)
recordcounttxt. Text = pstrfields(0)
line_num += 1
Loop
psrdCurrent.Clo se() ' Closes File
End Sub
Public Sub save()
Dim line_num As Integer
Dim filename2 As String
Dim csv_text As String
csv_text = recordcounttxt. Text & "," & companytxt.Text & "," &
Nametxt.Text & "," & addrtxt.Text & "," & citytxt.Text & "," &
statetxt.Text & "," & ziptxt.Text & "," & countrytxt.Text & "," &
phonetxt.Text & "," & faxtxt.Text & "," & celltxt.Text & "," &
titletxt.Text & "," & assistanttxt.Te xt & "," & urltxt.Text & "," &
altcontacttxt.T ext & "," & altphonetxt.Tex t & "," & altaddrtxt.Text &
"," & altcitytxt.Text & "," & altstatetxt.Tex t & "," & altziptxt.Text &
"," & territorytxt.Te xt & "," & mech1serialnum. Text & "," &
mech1vacpump.Te xt & "," & mech1spindle.Te xt & "," &
mech1vacpumpser ialnum.Text & "," & mech1filterpart num.Text & "," &
mech2serialnum. Text & "," & mech2vacpump.Te xt & "," & mech2spindle.Te xt
& "," & mech2vacpumpser ialnum.Text & "," & mech2filterpart num.Text &
"," & mech3serialnum. Text & "," & mech3vacpump.Te xt & "," &
mech3spindle.Te xt & "," & mech3vacpumpser ialnum.Text & "," &
mech3filterpart num.Text & "," & mech4serialnum. Text & "," &
mech4vacpump.Te xt & "," & mech4spindle.Te xt & "," &
mech4vacpumpser ialnum.Text & "," & mech4filterpart num.Text & "," &
user1txt.Text & "," & user2txt.Text & "," & user3txt.Text & "," &
user4txt.Text & "," & user5txt.Text & "," & user6txt.Text & "," &
user7txt.Text & "," & user8txt.Text & "," & user9txt.Text & "," &
user10txt.Text & "," & user11txt.Text & "," & user12txt.Text & "," &
user13txt.Text & "," & user14txt.Text & "," & user15txt.Text
filename2 = "WRITE FILENAME"
Dim filename As String
filename = "READ FILENAME"
' Create an empty string array to return to caller.
Dim lines() As String = {}
' Check to see if the file exists.
If File.Exists(fil ename) Then
' Open a stream reader to get the text from the file.
Dim sr As New StreamReader(fi lename)
' Read all the file text.
Dim fileText As String = sr.ReadToEnd()
' Close the stream reader
sr.Close()
' Split the text into a string array delimited by Carriage
Return/Line Feed.
lines = Split(fileText, vbCrLf)
' Return
Dim fs As New FileStream(file name2, FileMode.Create )
Dim sw As New StreamWriter(fs )
Dim foundBlank As Boolean
For Each line As String In lines
If line.Length > 0 Then
line_num += 1
If line_num = currecord Then
sw.WriteLine(cs v_text)
' Reset blank line flag
foundBlank = False
Else
sw.WriteLine(li ne)
' Reset blank line flag
foundBlank = False
End If
Else
If Not foundBlank Then
' Blank line: write first one
sw.WriteLine()
' Set flag to indicate that blank line was
found
foundBlank = True
End If
End If
Next
sw.Close()
fs.Close()
End If
If System.IO.File. Exists(filename 2) = True Then
If System.IO.File. Exists(filename ) = True Then
System.IO.File. Delete(filename )
End If
System.IO.File. Copy(filename2, filename)
End If
End Sub
-- END CODE --
--CSV format--
client_id,compa ny,Name,addr,ci ty,state,zip,co untry,phone,fax ,cell,title,ass istant,url,altc ontact,altphone ,altaddr,altcit y,altstate,altz ip,territory,me ch1serialnum,me ch1vacpump,mech 1spindle,mech1v acpumpserialnum ,mech1filterpar tnum,mech2seria lnum,mech2vacpu mp,mech2spindle ,mech2vacpumpse rialnum,mech2fi lterpartnum,mec h3serialnum,mec h3vacpump,mech3 spindle,mech3va cpumpserialnum, mech3filterpart num,mech4serial num,mech4vacpum p,mech4spindle, mech4vacpumpser ialnum,mech4fil terpartnum,user 1,user2,user3,u ser4,user5,user 6,user7,user8,u ser9,user10,use r11,user12,user 13,user14,user1 5
--end csv format--
I have some code to read the file and put the record into an array then
into textboxes. the problem is it seems to read everyother line of the
file not everyline at first I thought it might be the code then the csv
file The csv is a mysql generated via webmin however I cant seem to
find the problem anywhere so please advise.
-- CODE--
Public Sub csv_conn()
'Opens CSV File reads contents Writes them to an Array then
Sets values to textboxes
Call save()
Dim line_num As Integer
Dim psrdCurrent As System.IO.Strea mReader
Dim psrdline As String
Dim pstrfields() As String
Dim filename As String
filename = "READ FILENAME"
psrdCurrent = New System.IO.Strea mReader(filenam e) ' OPen File
psrdline = psrdCurrent.Rea dLine()
Do Until line_num = currecord
Dim psrdfile As String
psrdfile = psrdline & CrLf
psrdline = psrdCurrent.Rea dLine()
Dim currentlinevalu e As String
currentlinevalu e = psrdCurrent.Rea dLine()
pstrfields = Split(psrdline, ",") ' Parses document into an
Array with a , seperated value.
companytxt.Text = pstrfields(1) ' Setting Text to Textboxes
Nametxt.Text = pstrfields(2)
addrtxt.Text = pstrfields(3)
citytxt.Text = pstrfields(4)
statetxt.Text = pstrfields(5)
ziptxt.Text = pstrfields(6)
countrytxt.Text = pstrfields(7)
phonetxt.Text = pstrfields(8)
faxtxt.Text = pstrfields(9)
celltxt.Text = pstrfields(10)
titletxt.Text = pstrfields(11)
assistanttxt.Te xt = pstrfields(12)
urltxt.Text = pstrfields(13)
altcontacttxt.T ext = pstrfields(14)
altphonetxt.Tex t = pstrfields(15)
altaddrtxt.Text = pstrfields(16)
altcitytxt.Text = pstrfields(17)
altstatetxt.Tex t = pstrfields(18)
altziptxt.Text = pstrfields(19)
altcountrytxt.T ext = pstrfields(20)
user1txt.Text = pstrfields(21)
user2txt.Text = pstrfields(22)
user3txt.Text = pstrfields(23)
user4txt.Text = pstrfields(24)
user5txt.Text = pstrfields(25)
user6txt.Text = pstrfields(26)
user7txt.Text = pstrfields(27)
user8txt.Text = pstrfields(28)
user9txt.Text = pstrfields(29)
user10txt.Text = pstrfields(30)
user11txt.Text = pstrfields(31)
user12txt.Text = pstrfields(32)
user13txt.Text = pstrfields(33)
user14txt.Text = pstrfields(34)
user15txt.Text = pstrfields(35)
territorytxt.Te xt = pstrfields(26)
recordcounttxt. Text = pstrfields(0)
line_num += 1
Loop
psrdCurrent.Clo se() ' Closes File
End Sub
Public Sub save()
Dim line_num As Integer
Dim filename2 As String
Dim csv_text As String
csv_text = recordcounttxt. Text & "," & companytxt.Text & "," &
Nametxt.Text & "," & addrtxt.Text & "," & citytxt.Text & "," &
statetxt.Text & "," & ziptxt.Text & "," & countrytxt.Text & "," &
phonetxt.Text & "," & faxtxt.Text & "," & celltxt.Text & "," &
titletxt.Text & "," & assistanttxt.Te xt & "," & urltxt.Text & "," &
altcontacttxt.T ext & "," & altphonetxt.Tex t & "," & altaddrtxt.Text &
"," & altcitytxt.Text & "," & altstatetxt.Tex t & "," & altziptxt.Text &
"," & territorytxt.Te xt & "," & mech1serialnum. Text & "," &
mech1vacpump.Te xt & "," & mech1spindle.Te xt & "," &
mech1vacpumpser ialnum.Text & "," & mech1filterpart num.Text & "," &
mech2serialnum. Text & "," & mech2vacpump.Te xt & "," & mech2spindle.Te xt
& "," & mech2vacpumpser ialnum.Text & "," & mech2filterpart num.Text &
"," & mech3serialnum. Text & "," & mech3vacpump.Te xt & "," &
mech3spindle.Te xt & "," & mech3vacpumpser ialnum.Text & "," &
mech3filterpart num.Text & "," & mech4serialnum. Text & "," &
mech4vacpump.Te xt & "," & mech4spindle.Te xt & "," &
mech4vacpumpser ialnum.Text & "," & mech4filterpart num.Text & "," &
user1txt.Text & "," & user2txt.Text & "," & user3txt.Text & "," &
user4txt.Text & "," & user5txt.Text & "," & user6txt.Text & "," &
user7txt.Text & "," & user8txt.Text & "," & user9txt.Text & "," &
user10txt.Text & "," & user11txt.Text & "," & user12txt.Text & "," &
user13txt.Text & "," & user14txt.Text & "," & user15txt.Text
filename2 = "WRITE FILENAME"
Dim filename As String
filename = "READ FILENAME"
' Create an empty string array to return to caller.
Dim lines() As String = {}
' Check to see if the file exists.
If File.Exists(fil ename) Then
' Open a stream reader to get the text from the file.
Dim sr As New StreamReader(fi lename)
' Read all the file text.
Dim fileText As String = sr.ReadToEnd()
' Close the stream reader
sr.Close()
' Split the text into a string array delimited by Carriage
Return/Line Feed.
lines = Split(fileText, vbCrLf)
' Return
Dim fs As New FileStream(file name2, FileMode.Create )
Dim sw As New StreamWriter(fs )
Dim foundBlank As Boolean
For Each line As String In lines
If line.Length > 0 Then
line_num += 1
If line_num = currecord Then
sw.WriteLine(cs v_text)
' Reset blank line flag
foundBlank = False
Else
sw.WriteLine(li ne)
' Reset blank line flag
foundBlank = False
End If
Else
If Not foundBlank Then
' Blank line: write first one
sw.WriteLine()
' Set flag to indicate that blank line was
found
foundBlank = True
End If
End If
Next
sw.Close()
fs.Close()
End If
If System.IO.File. Exists(filename 2) = True Then
If System.IO.File. Exists(filename ) = True Then
System.IO.File. Delete(filename )
End If
System.IO.File. Copy(filename2, filename)
End If
End Sub
-- END CODE --
--CSV format--
client_id,compa ny,Name,addr,ci ty,state,zip,co untry,phone,fax ,cell,title,ass istant,url,altc ontact,altphone ,altaddr,altcit y,altstate,altz ip,territory,me ch1serialnum,me ch1vacpump,mech 1spindle,mech1v acpumpserialnum ,mech1filterpar tnum,mech2seria lnum,mech2vacpu mp,mech2spindle ,mech2vacpumpse rialnum,mech2fi lterpartnum,mec h3serialnum,mec h3vacpump,mech3 spindle,mech3va cpumpserialnum, mech3filterpart num,mech4serial num,mech4vacpum p,mech4spindle, mech4vacpumpser ialnum,mech4fil terpartnum,user 1,user2,user3,u ser4,user5,user 6,user7,user8,u ser9,user10,use r11,user12,user 13,user14,user1 5
--end csv format--
Comment