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
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
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.
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
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
"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 - Dim sCSVLine() as String
-
Dim sCSVElements() as String
-
Dim I as String
-
-
sCSVLine = Split(sCSVData, vbcrlf)
-
-
For I = 0 to Ubound(sCSVLine)
-
-
sCSVElements = Split(sCSVLine(I), ",")
-
-
'at this point you will have each element of one line of the csv to process as you need.
-
-
-
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.
"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 - Dim sCSVLine() as String
-
Dim sCSVElements() as String
-
Dim I as String
-
-
sCSVLine = Split(sCSVData, vbcrlf)
-
-
For I = 0 to Ubound(sCSVLine)
-
-
sCSVElements = Split(sCSVLine(I), ",")
-
-
'at this point you will have each element of one line of the csv to process as you need.
-
-
-
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?
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?
- Dim sCSVLine() as String
-
Dim sCSVElements() as String
-
Dim I as String
-
Dim lTime() as Long
-
Dim lCSVCount as Long
-
Dim sTime as String
-
-
sCSVLine = Split(sCSVData, vbcrlf)
-
lCSVCount = Ubound(sCSVLine)
-
Redim lTime(lCSVCount)
-
-
'start at 1 because the first set of values is just the header
-
For I = 1 to lCSVCount
-
sCSVElements = Split(sCSVLine(I), ",")
-
'i believe element 3 contains the value you want
-
sTime = Trim$(Replace(sCSVElements(3), "us"))
-
if IsNumeric(sTime) = True then
-
lTime(I) = cLng(sTime)
-
else
-
lTime(I) = -1
-
end if
-
DoEvents 'this is here to give the OS a break from this rather tight loop
-
Next I
-
'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.
- Dim sCSVLine() as String
-
Dim sCSVElements() as String
-
Dim I as String
-
Dim lTime() as Long
-
Dim lCSVCount as Long
-
Dim sTime as String
-
-
sCSVLine = Split(sCSVData, vbcrlf)
-
lCSVCount = Ubound(sCSVLine)
-
Redim lTime(lCSVCount)
-
-
'start at 1 because the first set of values is just the header
-
For I = 1 to lCSVCount
-
sCSVElements = Split(sCSVLine(I), ",")
-
'i believe element 3 contains the value you want
-
sTime = Trim$(Replace(sCSVElements(3), "us"))
-
if IsNumeric(sTime) = True then
-
lTime(I) = cLng(sTime)
-
else
-
lTime(I) = -1
-
end if
-
DoEvents 'this is here to give the OS a break from this rather tight loop
-
Next I
-
'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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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,
|
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
|
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.
|
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
|
by: uspramod |
last post by:
hi
the source is an excel file it is pivoted, i want to do unpivoting using vbscript
regards
Pramod
| |
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
|
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
|
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>
|
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 %>-->
|
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.
|
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: 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...
|
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...
|
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: 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
|
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...
| |