473,405 Members | 2,287 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,405 software developers and data experts.

Count occurences of a value in a column

3
I need to know how to count the number of "1s" in a column and then input the total number of "1s" in that column on the screen.
Hence counting the total of these numbers in this column.
PLEASE HELP ME!
I will be forever greatful to you if you do!!
Jul 31 '07 #1
9 1545
fplesco
82
I need to know how to count the number of "1s" in a column and then input the total number of "1s" in that column on the screen.
Hence counting the total of these numbers in this column.
PLEASE HELP ME!
I will be forever greatful to you if you do!!
Hi -

This is quite like a high level perspective of your problem but as I see it.

Expand|Select|Wrap|Line Numbers
  1. For Row = 1 to TotalRows 
  2.       intColTotalOne = 0
  3.       For Cols = 1 to TotalCols
  4.             if <Grid Object>.Textmatrix(Row,Cols) = "1" then 
  5.                'OR CINT(<GridObject>.Textmatrix(Row,Cols)) = 1
  6.                 intColTotalOne = intColTotalOne + 1
  7.             end if
  8.      Next Row
  9.  
  10.      Print intColTotalOne
  11. Next Row
  12.  
Aug 1 '07 #2
Killer42
8,435 Expert 8TB
I need to know how to count the number of "1s" in a column and then input the total number of "1s" in that column on the screen.
Hence counting the total of these numbers in this column.
You might want to check your wording, for a start. If you input the number (that is, accept it from the user via keyboard or whatever), then you don't need to calculate it.

Can you give us some more details about the situation? For instance, what version of VB are you using? What kind of "column" are you talking about? Something in Excel or Access, perhaps?

We're not mind-readers.
Aug 1 '07 #3
Killer42
8,435 Expert 8TB
... For Row = 1 to TotalRows ...
Thanks for taking a shot at it, fplesco. However, I would question your logic. It looks to me as though you are tallying up and displaying the "1"s per row, not those in a particular column.
Aug 1 '07 #4
hariharanmca
1,977 1GB
Thanks for taking a shot at it, fplesco. However, I would question your logic. It looks to me as though you are tallying up and displaying the "1"s per row, not those in a particular column.
yes you are correct Killer, and need change the for loop's Rows to Column and column into Rows or with help of arraylist he has to print.
Aug 1 '07 #5
Killer42
8,435 Expert 8TB
yes you are correct Killer, and need change the for loop's Rows to Column and column into Rows or with help of arraylist he has to print.
If we assume that the OP is using some sort of grid which allows direct access to each cell, as in the posted code, then a requirement to work with a particular column doesn't need nested loops at all. Just one loop, to go through the rows.
Aug 1 '07 #6
fplesco
82
Thanks for taking a shot at it, fplesco. However, I would question your logic. It looks to me as though you are tallying up and displaying the "1"s per row, not those in a particular column.

I got it wrong. I agree with you guys.

Thanks
Aug 2 '07 #7
hariharanmca
1,977 1GB
If we assume that the OP is using some sort of grid which allows direct access to each cell, as in the posted code, then a requirement to work with a particular column doesn't need nested loops at all. Just one loop, to go through the rows.
i cannot get what you mean
which allows direct access to each cell.

If he wants for a single column count. yha it's possible in one 'for'. But if it is contain multipule colume and rows, we have to use 2 'for' loop?
Aug 2 '07 #8
bexxx
3
Ok so ive thought about it and what i really need is a simple count function to go down the column and count the "1"s. Here ill give you an example:
This is what VB prints on the screen (it is information retreived from a Microsoft Excel File)

1 3 4
2 5 1
4 3 2
4 3 1
1 4 3
3 3 5

So i want the code to be able to go:
ok in column 1:
1 = 2
2 = 1
3 = 1
4 = 2
Etc. I want it to do this for all three columns and print the values on screen.
Does anyone know how to do this???
Aug 3 '07 #9
Killer42
8,435 Expert 8TB
If he wants for a single column count. yha it's possible in one 'for'. But if it is contain multipule colume and rows, we have to use 2 'for' loop?
How many rows or columns are contained in a grid is irrelevant. You only need the nested loops if you want to process multiple columns in multiple rows. That was not what the original question stated. To process a single column, you just need to loop through the rows, accessing the same column each time around the loop.

Anyway, I think this is one of those cases where we're both just saying the same thing, different ways.
Aug 3 '07 #10

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

Similar topics

2
by: Niklas E | last post by:
Does anyone know how to get all nodes in a xml-document that start with a certain text? In my case I want to count all suppliers ( <id>Supplier*</id> ) <root> <customer> <name>ABC</name>...
0
by: chris.bender | last post by:
1. My problem: I am using a query to populate a Chart in MS Access 2k. 2. My query: SELECT .Status, ., Sum(.Amount) AS SumOfAmount, Sum(IIf(!="Debit",!,!*-1)) AS realAmount, Count(.Status) AS...
1
by: JD | last post by:
Hi guys I'm trying to write a program that counts the occurrences of HTML tags in a text file. This is what I have so far: #include <stdio.h> #include <stdlib.h> #include <string.h> ...
1
by: sunilkeswani | last post by:
Hi I am still new to access. I want to know how i can build a query which can display results from 4 different columns/fields Like. Field1 Field2 Field3 Field4 1 2 1 ...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
2
by: DrewKull | last post by:
Ok ... so I'm looking at a query where im trying to show a bunch of columns counted up based on criteria ... So far i've been able to count all the rows up and show them ... and also count up...
0
by: uninvitedm | last post by:
Heya I've got a table of invoices, which have dates and customer_id's. What I need to get is the number of occurances for this customer for a 12-month range window. For example, if there's an...
5
by: Larry | last post by:
Dear all, I'm new to Python. I have a file (an image file actually) that I need to read pixel by pixel. It's an 8-bit integer type. I need to get the statistics like mean, standard deviation,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
agi2029
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,...
0
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...

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.