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-- 1 1546
BBepristis,
Just read the file in with
mystring = reader.readtoen d
than split that with
dim mystringarray as string() = mystring.split( " "c)
I hope this helps,
Cor
"bbepristis " <br************ *@gmail.com> schreef in bericht
news:11******** **************@ v46g2000cwv.goo glegroups.com.. . 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-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Olaf Noehring |
last post by:
Hi
I am the administrator of TSEP - The Search Engine Project (www.tsep.info).
We developer are unclear about the speed of two different methods:
Is it faster to
a) write to a file
or
b) update a record in a database
Olaf
|
by: muser |
last post by:
With the following code I'm trying to read a text file (infile) and
output inaccuracies to the error file (printerfile). The text file is
written and stored on disk, while the printerfile has to be created
when the program executes. But the compile keeps reading that it can't
find the text file.
Karl you wrote the original program from which this one is but a poor
copy, can you or anyone else enlighten me as to why yours worked and
mine...
|
by: muser |
last post by:
The following program reads two lines of a file in my A drive and
reads no more.
Can some sarmartian tell me why that is. Please copy and paste the
program into your own compiler please.
program is this.
#include <iostream>
#include <iomanip>
#include <fstream>
|
by: happy |
last post by:
/* Book name : The prodessional programmers guide to C
File name : E:\programs\tc\iti01\ch09\main\01setupm.c
Program discription: file setuping -up -Version 01-ver01-W
Logic :
1-open file for output
2-while more customers
2-1-input customers record
2-2-write customer record to file
3-write end of file record to file
4-close file
|
by: Need Helps |
last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:
mdyn"comment~""comment~"\n
Now, I wrote some code to read these records, and it works perfectly for every date I've tried it on, except when the day is 26. I tried saving a record for 6/26/2004 and 7/26/2004 and it read it in as the day, year, and number of...
| |
by: DraguVaso |
last post by:
Hi,
I need a FAST way to put the content of a file in a datatable (one record
for each line in the file).
I have a routine for it, but it takes me too much time (2-5 seconds for each
file) to put the lines in the datatable and do some actions. Does anybody
knows a faster method? The fact is: I actually only need the lines starting
with "0*" and "1*".
|
by: muttu2244 |
last post by:
Hi everybody
Am trying to read a csv file "temp.csv", which has the below info,
compName macAddr ipAddr
opSys
|
by: sherifffruitfly |
last post by:
Hi,
I've a got a little (exercise) program that reads data from a file and
puts it into struct members. I run into trouble when one of the data
pieces is comprised of several words (eg "john doe", with a space in
it).
For console input, cin.getline(var, howMuchIWant) or cin.get() has done
the trick for me in the past. It doesn't seem to work for me nearly so
well with a file stream. I wouldn't have thought cpp regarded
|
by: Timofmars |
last post by:
I'm try to Unload DB2 data from a table into a record sequential file
on NT. I can an unload on Mainframe, but it doesn't seem to be an
option in NT.
In NT, all I can do is export/import. I can do a Load too, but not an
Unload. I just want the only the data from the table in a record
sequential file. Export seems only to give options to have a delimited
line sequential file or a record sequential file where the data is
preceeded by...
|
by: Tom |
last post by:
I have a datafile which has a form of
10.10 10.20 10.30 ...
20.10 20.20 20.30 ...
30.10 30.20 30.30 ...
.. . .
.. . .
.. . .
it has 500 rows and 10002 colums.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |