Using Trends to predict when to order just-in-time

I am a newbie VB programmer.  I am in "advanced" programming in my school.  The first semester was about HTML coding and now we are learning about VB code.  The problem is, our school isn't that rich and the guy who is teaching the class doesn't have enough time to teach our class (he donated his time freely), so now my school is calling the class an "Independent Study" class (because he ins't teaching or helping us anymore).  Any ways, has given us our final project and we have little coding know-how to do his little wizard VB projects.

We are using the VB 4.0 that comes with Excel 95.  My project is "Inventory Management".  I have to use the TREND function to predict when to order stock, for just-in-time.  In my module, I would have something like this for code:

Do
OnHandRead = Application.InputBox("Number of Products Sold", "Enter on hand count", OnHand)
OnHand = IsNumeric(OnHandRead)
If OnHand = False Then MsgBox "Invalid Number", 16, "Error"
Loop Until OnHand = True
OnHand = OnHandRead

(and one for dates too) I was thinking of taking the dates and converting them back to real numbers and taking the TREND of that (i.e. 1/1/98 comes out to be around 36790 or something like that).  
So, lets say we have 39790, 39791, 39792, 39793, 39794 for the numbers for the dates, so TREND(39790, 39793, 39796, 39799, 39802) would produce 3 days for the trend, right?  Then, I could have 5,10,15,20,25 for each day for the number of products sold, so that TREND(5,10,15,20,25) would produce 5?  Then I could have them type in the original on-hand they had and setup something like this (assuming they originally had 100 on-hand):

pseudo-code
SomeVar = (100 - [30 / 3] * [5 * 1])  
If Somevar / OrginalOnHandCount < 40 then something...???

I am not sure what formula to use or how to set it up.  I already tried the TREND function in the module coding and didn't work.  Any formulas, coding or suggestions will taken gladly.

Thanks,

Adam Leinss
LVL 23
Adam LeinssServer SpecialistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

y96andhaCommented:
Please try this piece of code. It shows how to use the trend function. Please comment if you have any questions about it.


Dim numdates As Long
Dim value, flag As Long, currentstock As Long
Dim eachday As Single
numdates = 0
Worksheets.Add
ActiveSheet.StandardWidth = 30

Do
numdates = numdates + 1

value = ""
Do
value = Application.InputBox("Date for stock info", "Date", value)
flag = IsDate(value)
If flag = False Then MsgBox "Invalid date", 16, "Error"
Loop Until flag = True
ActiveSheet.Cells(numdates, 1).value = CVDate(value)

value = ""
Do
value = Application.InputBox("Number of items in stock", "Count", value)
flag = IsNumeric(value)
If flag = False Then MsgBox "Invalid Number", 16, "Error"
Loop Until flag = True
ActiveSheet.Cells(numdates, 2).value = value

Loop While MsgBox("More previous data?", vbYesNo) = vbYes

numdates = numdates + 1

ActiveSheet.Cells(numdates, 1).value = CVDate(CLng(Now))
value = ""
Do
value = Application.InputBox("Number of items currently in stock", "Count", value)
flag = IsNumeric(value)
If flag = False Then MsgBox "Invalid Number", 16, "Error"
Loop Until flag = True
ActiveSheet.Cells(numdates, 2).value = value
currentstock = value

ActiveSheet.Cells(numdates + 1, 1).value = ActiveSheet.Cells(numdates, 1).value + 1
ActiveSheet.Cells(1, 3).Formula = "=TREND(B1:B" & numdates & ",A1:A" & numdates & ",A" & numdates & ")"
ActiveSheet.Cells(2, 3).Formula = "=TREND(B1:B" & numdates & ",A1:A" & numdates & ",A" & numdates + 1 & ")"

eachday = ActiveSheet.Cells(1, 3).value - ActiveSheet.Cells(2, 3).value

daysleft = currentstock / eachday

MsgBox "We will run out of stock in " & CLng(daysleft) & " days"

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Adam LeinssServer SpecialistAuthor Commented:
Hi y96andha!  I appreciate the time you took to help me, you don't know how much it means to me!  I just have one question.  When I ran the code, I got "Run-time error 6,
Overflow".  When I clicked Debug, it went to the line:
"ActiveSheet.Cells(numdates,1).value = CVDate(value)".  Do you have any idea what the problem could be and any possible solution to it???

Thank you!
Adam Leinss


0
y96andhaCommented:
That is strange. I did not get the same error, I've never seen it. I just installed Excel for 95 and pasted all the code into a module and added sub Main and end sub at the beginning and end, and it worked immediately.

When you get the error, could you please use ?value in the debug window to get the contents of value and post it here? In what format did you enter the date? I have used both "1997-05-16" and "16/5/97", and both worked OK.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Adam LeinssServer SpecialistAuthor Commented:
I entered the date as "12/12/98" and when I typed ?value in the debug box, it gave me "12/12/98"?  I will delete and re-install Excel and see if that helps. If it works on your Excel 95 version then it has to work on mine! :)

Thanks,
Adam
0
Adam LeinssServer SpecialistAuthor Commented:
Well, I tried to re-install Excel 95 and I still get the same answer.  When I try ?CVdate(value), I get the overflow error again?  Maybe its something with my computer, I will try it at the school's computer lab on tuesday and see if it works there.

Thanks,
Adam
0
y96andhaCommented:
That is very strange indeed.

I just tested, this is copied directly from my debug window in Excel 95:

?cvdate("12/12/98")
1998-12-12
value="12/12/98"
?value
12/12/98
?cvdate(value)
1998-12-12

Could you try some other combinations, like ?cvdate("1998-12-12"), ?now and ?cvdate(now)?

0
Adam LeinssServer SpecialistAuthor Commented:
These are the first things I tried from the Debug Window

?cvdate("12/12/98")
12/12/98

value="12/12/98"
?value
12/12/98

?cvdate(value)
[after I do the last one {?cvdate(value)}, I get a overflow error]

Second batch:
?cvdate("1998-12-12")
12/12/98

?now
5/17/97 11:15:44 PM
?cvdate(now)
[after I do the last one {?cvdate(now)}, I get a overflow error]



0
y96andhaCommented:
Hmm.. Try using CDate instead of CVDate, see if that helps.
I guess it must have something to do with the country settings. I live in Sweden, and use Swedish Excel and Windows NT, so my standard date format is 1997-05-17.


0
Adam LeinssServer SpecialistAuthor Commented:
Ok, this will be the last time I bother you! :) I took the code to school and it worked!? Go figure, my Excel 95 must be corrupted in some way.  Any ways, now that the coding actually works, I have some questions on exactly how it works.

The first set of questions, is the programming asking how many are sold per day or how many you received of that item on that day?

For the second set of questions, is it asking how much stock you have left over or the total stock you had to begin with?  When it entered 12/1/98 and enter, lets say, 25, and answer no, it gives a date of 5/21/98.  Over what period of time is the program basing it calculations?  A month?  Six months?

Thanks for all your help!

Adam
0
y96andhaCommented:
The example only demonstrates how to fit a line to a number of samples. It will only work to calculate the average consumption during a period of time.

You enter the number of items in stock at certain dates in the past, and then you enter the number currently in stock. The program will calculate the average daily consumption using the TREND function, and then display the number of days left until all of the stock has been used up at that rate.

I do not really know how much mathematics you know. It would be easier to discuss in E-mails, could you mail me at andreas.hansson@mbox303.swipnet.se?





0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.