Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert function into Class module

Status
Not open for further replies.

neemi

Programmer
May 14, 2002
519
GB
How can I change this function into an object ie class module so that I can return either the

DiaryDue value
vtDueDays value
vtDueHrs value
vtDueMins value

by typing soming like DiaryDue.vtdueDays or DiaryDue.vtdueMins etc

Please help...
The function is:

Code:
Public Function DiaryDue(vtRemDateTime As Variant) As Variant

Dim vtRemDate As Variant
Dim vtRemTime As Variant

Dim vtDueDays As Variant
Dim vtDueHrs As Variant
Dim vtDueMins As Variant

Dim CurrentDate As Variant
Dim CurrentTime As Variant

CurrentDate = Date
CurrentTime = Time

vtRemDate = Format(vtRemDateTime, "DD/MM/YYYY")
vtRemTime = Format(vtRemDateTime, "HH:NN:SS")

vtDueDays = DateDiff("d", vtRemDate, CurrentDate)
vtDueHrs = Int(DateDiff("n", vtRemTime, CurrentTime) / 60)
vtDueMins = DateDiff("n", vtRemTime, CurrentTime) - Int(DateDiff("n", vtRemTime, CurrentTime) / 60) * 60

If vtDueDays > 0 Then
    If vtDueDays > 1 Then
        DiaryDue = vtDueDays & " days overdue"
    Else
        DiaryDue = 1 & " day overdue"
    End If

ElseIf vtDueHrs > 0 Then
    If vtDueHrs > 1 Then
        DiaryDue = vtDueHrs & " hrs "
    Else
        DiaryDue = 1 & " hr "
    End If

    If vtDueMins > 0 Then
        If vtDueMins > 1 Then
            DiaryDue = DiaryDue & vtDueMins & " mins"
        Else
            DiaryDue = DiaryDue & 1 & " min"
        End If
    End If
    
    DiaryDue = DiaryDue & " overdue"
   
Else

    If vtDueHrs < 0 Then
        vtDueHrs = Int(DateDiff("n", CurrentTime, vtRemTime) / 60)
        If CurrentTime < vtRemTime Then
            vtDueMins = DateDiff("n", CurrentTime, vtRemTime) - Int(DateDiff("n", CurrentTime, vtRemTime) / 60) * 60
        End If
        
        If vtDueHrs > 0 Then
            If vtDueHrs > 1 Then
                DiaryDue = vtDueHrs & " hrs "
            Else
                DiaryDue = 1 & " hr "
            End If
        End If
        
        If vtDueMins > 0 Then
            If vtDueMins > 1 Then
                DiaryDue = DiaryDue & vtDueMins & " mins"
            Else
                DiaryDue = DiaryDue & 1 & " min"
            End If
        End If
        
        'DiaryDue = "Due in " & DiaryDue
        
    Else
        
        If vtDueMins < 0 Then
        
            If vtDueHrs < 0 Then
                If vtDueHrs * (-1) = 1 Then
                    DiaryDue = vtDueHrs * (-1) & " hour"
                Else
                    DiaryDue = vtDueHrs * (-1) & " hours"
                End If
            Else
                DiaryDue = vtDueMins * (-1) & " minutes"
            End If
            
        ElseIf vtDueMins > 1 Then
            DiaryDue = vtDueMins & " minutes overdue"
        Else
            DiaryDue = 1 & " minute overdue"
        End If
    End If
    
End If

'Int(DateDiff("n",[RemTime],Time())/60)

End Function
 
It is not necessary to create custom class, rather define new type and declare your function as this type.

If you like class, add class module and programme it: public variables and property procedyres become properties, functions and subs become methods.

combo
 



Hi,

To continue from combo's post...

"How can I change this function into ... so that I can return either the

DiaryDue value
vtDueDays value
vtDueHrs value
vtDueMins value

Code:
Public Function DiaryDue(vtRemDateTime As Variant, nItem) As Variant

   Select Case nItem
     Case 1    'DiaryDue 
       'your code here
       DiaryDue = Somevalue
     Case 2    'vtDueDays 
       'your code here
       DiaryDue = Somevalue
     Case 3    'vtDueHrs 
       'your code here
       DiaryDue = Somevalue
     Case 4    'vtDueMins 
       'your code here 
       DiaryDue = Somevalue
   End select

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top