View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default If this is impossible, just tell me.

On Fri, 04 Jun 2004 16:23:13 -0400, Ron Rosenfeld
wrote:

I missed something in your first posting. The code below compares the warranty
period with today's date. You'll need to pass that parameter to the function
and also change the DATE parameter Date Returned. So try the following
modifications on the lines not preceded by a "greater than" sign ().

==============================
Option Explicit
Public Infostr As Variant


Function InWarrantyCount(DateReturned, WarrantyPeriod, Info) As Integer

Dim i As Integer
Dim dt1 As Date

Infostr = Split(Info, ", ")

If InStr(1, Infostr(0), "S/N") = 0 Then
MsgBox ("No S/N")
Exit Function
End If

Infostr(0) = Mid(Infostr(0), InStr(1, Infostr(0), "S/N") + 4, 255)

For i = 0 To UBound(Infostr)
dt1 = ConvertDate(Infostr(i))

If DateDiff("m", dt1, DateReturned) <= WarrantyPeriod Then
InWarrantyCount = InWarrantyCount + 1
End If
Next i

End Function


Function OutWarrantyCount(DateReturned, WarrantyPeriod, Info) As Integer

OutWarrantyCount = InWarrantyCount(WarrantyPeriod, Info)
OutWarrantyCount = UBound(Infostr) + 1 - OutWarrantyCount
End Function

Private Function ConvertDate(dt) As Date
Dim yr As Integer, month As Integer
Dim MonthPos As Integer
Const day As Integer = 1

If IsNumeric(Left(dt, 2)) Then
yr = 2000 + Left(dt, 2)
MonthPos = 3
Else
yr = 1990 + Left(dt, 1)
MonthPos = 2
End If

month = Asc(Mid(dt, MonthPos, 1)) - 64

ConvertDate = DateSerial(yr, month, day)

End Function
=====================


--ron


--ron