?
Solved

Counting sales

Posted on 2007-12-02
4
Medium Priority
?
298 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 1050 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

764 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