473,748 Members | 6,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read data from csv file using VBScript

8 New Member
I would like to read a column of data in csv file on each rows and get the data to perform calculation as shown below:

"Sample Number","POD1", "POD5","Tim e"
803,E7,03,
1803,E7,03,3.33 30 us
2803,E7,03,3.33 30 us
3803,E7,03,3.33 30 us
4803,E7,03,3.33 45 us
5803,E7,03,3.33 30 us
6803,E7,03,3.33 30 us
7803,E7,03,3.33 30 us
8803,E7,03,3.33 30 us
9803,E7,03,3.33 45 us

I will need to read the values in the last column 3.3330 u and use this value to convert it to frequency. Note the 3.3330us is in second which means it reads as 3.3330micro second. I would also like to repeat it for every rows until end, how should i perform that. Please help me to come out with simple vbscript command on that.Thank you
Jul 10 '08 #1
8 22702
gpraghuram
1,275 Recognized Expert Top Contributor
If its in C or C++ i can help u.
Since its in VB why cant u try posting this in .NET forum

Raghu
Jul 10 '08 #2
Banfa
9,065 Recognized Expert Moderator Expert
Since its in VB why cant u try posting this in .NET forum

Raghu
Better still try posting in the VB forum :D

I am moving this post to a more relevant forum anyway.
Jul 10 '08 #3
meiliong
8 New Member
If its in C or C++ i can help u.
Since its in VB why cant u try posting this in .NET forum

Raghu
Raghu, thanks for your proposal.

Can you show to me if it is running using C++? I need to learn as well.

meiliong
Jul 11 '08 #4
gpraghuram
1,275 Recognized Expert Top Contributor
Raghu, thanks for your proposal.

Can you show to me if it is running using C++? I need to learn as well.

meiliong
I think this is moved to new forum...why cant u post a new thread for this...in C++ forum

raghu
Jul 11 '08 #5
!NoItAll
297 Contributor
"Sample Number","POD1", "POD5","Tim e"
803,E7,03,
1803,E7,03,3.33 30 us
2803,E7,03,3.33 30 us
3803,E7,03,3.33 30 us
4803,E7,03,3.33 45 us
5803,E7,03,3.33 30 us
6803,E7,03,3.33 30 us
7803,E7,03,3.33 30 us
8803,E7,03,3.33 30 us
9803,E7,03,3.33 45 us


Assuming you know how to put the data into a variable - we'll call it sCSVData

Expand|Select|Wrap|Line Numbers
  1. Dim sCSVLine() as String
  2. Dim sCSVElements() as String
  3. Dim I as String
  4.  
  5. sCSVLine = Split(sCSVData, vbcrlf)
  6.  
  7. For I = 0 to Ubound(sCSVLine)
  8.  
  9. sCSVElements = Split(sCSVLine(I), ",")
  10.  
  11. 'at this point you will have each element of one line of the csv to process as you need.
  12.  
  13.  
  14. Next I

Danger: CSV files can be delimited with just commas, or commas and quotes. This routine does NOT work with commas and quotes - just the data you provided.
Jul 12 '08 #6
meiliong
8 New Member
"Sample Number","POD1", "POD5","Tim e"
803,E7,03,
1803,E7,03,3.33 30 us
2803,E7,03,3.33 30 us
3803,E7,03,3.33 30 us
4803,E7,03,3.33 45 us
5803,E7,03,3.33 30 us
6803,E7,03,3.33 30 us
7803,E7,03,3.33 30 us
8803,E7,03,3.33 30 us
9803,E7,03,3.33 45 us


Assuming you know how to put the data into a variable - we'll call it sCSVData

Expand|Select|Wrap|Line Numbers
  1. Dim sCSVLine() as String
  2. Dim sCSVElements() as String
  3. Dim I as String
  4.  
  5. sCSVLine = Split(sCSVData, vbcrlf)
  6.  
  7. For I = 0 to Ubound(sCSVLine)
  8.  
  9. sCSVElements = Split(sCSVLine(I), ",")
  10.  
  11. 'at this point you will have each element of one line of the csv to process as you need.
  12.  
  13.  
  14. Next I

Danger: CSV files can be delimited with just commas, or commas and quotes. This routine does NOT work with commas and quotes - just the data you provided.
Thank you, but how about if i would like to grab the data and perform calculation for example 3.3330+3.3330+3 .3330+3.3330+3. 3330+3.3330+... .=xxxx?How should i proceed from here?
Jul 13 '08 #7
!NoItAll
297 Contributor
Thank you, but how about if i would like to grab the data and perform calculation for example 3.3330+3.3330+3 .3330+3.3330+3. 3330+3.3330+... .=xxxx?How should i proceed from here?
Expand|Select|Wrap|Line Numbers
  1.   Dim sCSVLine() as String
  2.   Dim sCSVElements() as String
  3.   Dim I as String
  4.   Dim lTime() as Long
  5.   Dim lCSVCount as Long
  6.   Dim sTime as String
  7.  
  8. sCSVLine = Split(sCSVData, vbcrlf)
  9. lCSVCount = Ubound(sCSVLine)
  10. Redim lTime(lCSVCount)
  11.  
  12.    'start at 1 because the first set of values is just the header
  13.   For I = 1 to lCSVCount
  14.          sCSVElements = Split(sCSVLine(I), ",")
  15.          'i believe element 3 contains the value you want
  16.          sTime = Trim$(Replace(sCSVElements(3), "us"))
  17.          if IsNumeric(sTime) = True then
  18.               lTime(I) = cLng(sTime)  
  19.          else
  20.               lTime(I) = -1
  21.          end if
  22.          DoEvents   'this is here to give the OS  a break from this rather tight loop
  23.    Next I
  24.  
'when the loop is complete you will have (lCSVCount -1) (skip element 0) of the microsecond (us) values in the one dimensional lTime array. Now you can do something simple like ltime(1) + ltime(2) + ltime(3) etc...
Any invalid times will be -1 so you will want to skip those so it's best to do your math in a loop.
Jul 13 '08 #8
meiliong
8 New Member
Expand|Select|Wrap|Line Numbers
  1.   Dim sCSVLine() as String
  2.   Dim sCSVElements() as String
  3.   Dim I as String
  4.   Dim lTime() as Long
  5.   Dim lCSVCount as Long
  6.   Dim sTime as String
  7.  
  8. sCSVLine = Split(sCSVData, vbcrlf)
  9. lCSVCount = Ubound(sCSVLine)
  10. Redim lTime(lCSVCount)
  11.  
  12.    'start at 1 because the first set of values is just the header
  13.   For I = 1 to lCSVCount
  14.          sCSVElements = Split(sCSVLine(I), ",")
  15.          'i believe element 3 contains the value you want
  16.          sTime = Trim$(Replace(sCSVElements(3), "us"))
  17.          if IsNumeric(sTime) = True then
  18.               lTime(I) = cLng(sTime)  
  19.          else
  20.               lTime(I) = -1
  21.          end if
  22.          DoEvents   'this is here to give the OS  a break from this rather tight loop
  23.    Next I
  24.  
'when the loop is complete you will have (lCSVCount -1) (skip element 0) of the microsecond (us) values in the one dimensional lTime array. Now you can do something simple like ltime(1) + ltime(2) + ltime(3) etc...
Any invalid times will be -1 so you will want to skip those so it's best to do your math in a loop.
Thanks, i think it did actually gave me some idea. previously i did come out with my own code, is that mean if i wanted to add all the values on element 3 i just perform as above or how should i continue from my own code rather use the one you recommended?Tha nk you for your comment,i really appreciate it!

Const ForReading = 1
Set objFSO = CreateObject("S cripting.FileSy stemObject")
Set objTextFile = objFSO.OpenText File _
("c:\test2\test .txt", ForReading)

Do Until objTextFile.AtE ndOfStream
strNextLine = objTextFile.Rea dline
arrServiceList = Split(strNextLi ne , ",")
For i = 3 to Ubound(arrServi ceList)
Wscript.Echo "Service: " & arrServiceList( i)
Next
Loop
Jul 13 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
8710
by: Scott | last post by:
Is there a way to check if a file exist using VBScript in an ASP page. So the code might go something like this: If Exists("C:\Junk\1.txt") then Do something Else Do something else End If Thx,
5
7636
by: Mika M | last post by:
Hi! I'm trying to read text file like... "Field1";"Field2";"Field3";"Field4" "ABCD";"EFGH";"1234";"20051020" "AABB";"CCDD";"2468";"20051021" "CCDD";"XXYY";"4321";"20051022" ....using OLE DB-provider. Unfortunately I can't affect in what kind of
8
2920
by: Johnny | last post by:
Hi all: I have an ASP.NET form that reads an Excel file and populates a datagrid. If I load the form in IE on the server, and select a local file, the code works fine. However if I load the form in IE from a client (http://server/readexcel.aspx) and try to read a local Excel file, the file cannot be opened. I imagine it's some kind of a security problem in sending the Excel data back to the web server, but I am not sure.
1
8798
by: neveen | last post by:
i want to open and read text file using j2me that can run on mobile 6630 then i want to make button called read that when pressed the data inside text display
0
1818
by: uspramod | last post by:
hi the source is an excel file it is pivoted, i want to do unpivoting using vbscript regards Pramod
1
2672
by: =?Utf-8?B?c3Vpcw==?= | last post by:
Hi every body, i have a problem with how to read .MSG file (Outlook) using vb.net ? using this articles the author has already explain how to read .MSG file using stuctured storage (vc++) (http://www.codeguru.com/cpp/cpp/cpp_mfc/files/article.php/c13487/#more i wanted to know how to do this using vb.net ? simple mean is how to read the .MSG file using Stuctured Storage in .Net
5
3826
by: Rohit111111 | last post by:
Hello All, I new to ASP and i am using VBScript, I want to delete a file which is located on the remote machine hbow can i delete that file.plz help its urgent
7
2108
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
Hi, I am using visual studio C# window and I have an xml file which I need to read that file using Object Oriented program. What codes I should use in my class to load and read that xml file. Thanks My xml file call carsXml.xml and it includes below information: <?xml version="1.0" encoding="utf-8" ?> <carlot> <car> <Make>OldsMobile</Make>
5
7512
Soniad
by: Soniad | last post by:
Hello, I want to include asp file within vbscript, this file name i am taking in variable . and when i use this variable in the include tag outside delimiters(<%%>), it does not work, <%Dim AllocPath AllocPath = "SchemeAllocation/"&Trim(lcase(ProductName))&"/QuotaAlloc.asp" %> <!-- #include file=<%=AllocPath %>-->
4
4889
by: tokcy | last post by:
Hi everyone, I have some .rtf extension file and i want to read that file using php on html page but i am not able to do this. If it is .txt file then there is no problem but it is RTF and DOC file. Can any one tell me the soluion. i will be very thank full to all its very urgent.
0
8826
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,...
0
9534
Oralloy
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...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
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();...
0
4597
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...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2211
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.