Solved

Counting sales

Posted on 2007-12-02
4
252 Views
Last Modified: 2010-04-30
Hi Experts - Counting purchases by month.

I'm finding it difficult to compose a routine to count how many of 6 specific items are being sold to our 25-40yr old customers . Here's the data:

Dim StockCode as string (5)
StockCode (1) = "721"
StockCode (2) = "725"
StockCode (3) = "2620"
StockCode (4) = "2517"
StockCode (5) = "723"
StockCode (6)  = "727"

25 -40yr old customers ( text file of  approx 300 index numbers )
eg
16433
15634
15555
etc

All sales records (text file of approx 3000 sales to ALL customers)  ie  0-99yr old
eg
customer nr    (tab)       date        (tab)  item description,
   16433          (tab)  14/09/2007  (tab)          721

The output required is an excel report showing how many of each item were purchased by the  25-40yr old group (by month).

PURCHASES (25-40yr olds)   721's     725's     2620's    2517's     723's   727's
This month                                  16          72           8              25             2             1
Previous month                          14          63           5              .                .             .
-2 month                                       .
-3 month                                       .
etc
etc
till -23 months

Open in new window

0
Comment
Question by:peterdarazs
  • 2
4 Comments
 
LVL 4

Expert Comment

by:origfla
ID: 20393280
Simply work through the final file with all the data of sales and put it into a pivot table
Row = Date / Month
Column = Item Description
TableData = Count of Date
0
 

Author Comment

by:peterdarazs
ID: 20393320
Pl remember i'm a beginner at programming, - I can define variables, compose  loops, but still have difficulty with:
1/ reading the text data into arrays
2/ counting the data in the different array fields
3/ presenting the results as an excel file.

Many thanks
Peter

 
0
 
LVL 14

Accepted Solution

by:
steveberzins earned 350 total points
ID: 20393333
what version of VB?
I'm guessing 6, but, if you are using VB9 or .NET 3.5, you got lots better options...

assuming v6, first we'd need to break it down, and psuedo code out the steps, then put it into code.

so, lets tell the story first.

for each of the last 24 months, I want to know how many of each of these products I've sold to 25 to 40 year old customers.

so, first we create a collection of months

Dim months as Collection
set months = new Collection

Dim products as Collection

loop through and create a bunch of collections of collections
for i = 0 to -23 step -1
    Set products = new Collection
    products.add("721", 0)
    products.add("725", 0)
    etc...

    months.add(i, products)
next

so, now we have a collection of collections ready to store our data.

now we loop the file, line by line, see if the line
1. is one of our desired products
2. is in the date range
3. is for one of our target customers

if it is, we will have a place for it in our collections, we just add one to it

if it is, all you need to do is increment the proper item by adding one to it.

months(month)(product) = months(month)(product) + 1

or what it might look like with values rather than variables

months("-22")("721") = months("-22")("721") + 1

then, once we've looped all these records, we just loop the collection to output the data.

open excel application object in code, and write out the data....

for i = 0 to -23 step -1
     
    sheet1.cells(...) = months(i)("721")  
    sheet1.cells(...) = months(i)("725")  
    ....
   
next
0
 

Author Closing Comment

by:peterdarazs
ID: 31412237
Ok - that makes sense and I'll try put it into action. Many thanks and good luck.
Peter
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now