473,326 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Complex counting of items in CSV

Hey guys,

Is there a way to do the following?

After opening a CSV file, look in a column and count each of the unique items in it?

For example,
If I have 500GB Hard drives, 64GB Flash Drives and 6ft USB Cables, I want to be able to count up the totals for them?

The tricky part is finding unique items as they will always be different.

Do I need to "know" what my program will be actually looking for or is there a way to program it to just find unique items?

Here is the code I am working with which it currently finds TRUE items in one column.
Expand|Select|Wrap|Line Numbers
  1.  Dim startCounting As Boolean = False
  2.         Dim trueCount0 As Integer = 0
  3.         Dim csvFields() As String
  4.         For Each line As String In System.IO.File.ReadAllLines(FileName)
  5.             csvFields = line.Split(",")
  6.             If startCounting Then
  7.                 If csvFields(0) = String.Empty OrElse csvFields.Length < 23 Then
  8.                     Exit For
  9.                 ElseIf csvFields(23) = "True" Then
  10.                     trueCount0 += 1
  11.                 End If
  12.             ElseIf Not startCounting AndAlso csvFields.Length >= 23 AndAlso csvFields(23) = "Device_List" Then
  13.                 startCounting = True
  14.             End If
  15.         Next
  16.  
  17.         Label4.Text = String.Format("{0}", trueCount0)
  18.  
Mar 14 '13 #1
4 1273
Mikkeee
94 64KB
I would recommend using a hashtable with the key as the unique item name and the value as a counter. If the if the key isn't in the hashtable then add it and set the count to 1. If you do find the key then increment the value by 1.
EDIT:
I just realized that this is in a VB6 group. Use the same concept but instead use an array.
Mar 14 '13 #2
Sorry, it was put in the wrong group. It is for VB 2012

@Mikkeee
Mar 14 '13 #3
Mikkeee
94 64KB
Then a hashtable is the way to go.
Mar 14 '13 #4
Killer42
8,435 Expert 8TB
Just a quick cautionary note - CSV data can include commas within a field. So unless you know it won't in your file, simply splitting on commas may cause a mess.
Apr 4 '13 #5

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

Similar topics

16
by: It's me | last post by:
Okay, I give up. What's the best way to count number of items in a list? For instance, a=,4,5,] I want to know how many items are there in a (answer should be 7 - I don't want it to be 4)
1
by: Andrew Banks | last post by:
I have a table of product orders. It contains a row for "platform" and I need to return how many times each platform is listed in the DB Example data for platform could be: XBOX XBOX XBOX...
4
by: Rob Meade | last post by:
Hi all, Ok - I appreciated I could probably just do this : For Each item IN array intCount = intCount + 1 Next
1
by: zishiri | last post by:
My Operating System is Windows XP. I use Ms Access 2003 My problems are as follows 1. I want a textbox of one form(form2) to count the number of items in one database table and display the...
3
by: jas2803 | last post by:
Hello, I have a table: The person gets to come back as often as possible and choose between 3 different items, A, B C, for the column. They can take as many as they want, column. I want...
4
prn
by: prn | last post by:
Hi folks, I've got another (inherited) puzzle that I don't understand. A report that I need to modify contains a subreport that lists a variable number of items in its detail section and then...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.