Solved

Counting sales

Posted on 2007-12-02
4
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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