Link to home
Start Free TrialLog in
Avatar of Adam Leinss
Adam LeinssFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of y96andha
y96andha

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Adam Leinss

ASKER

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


Avatar of y96andha
y96andha

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.
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
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
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)?

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]



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.


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
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?