Link to home
Start Free TrialLog in
Avatar of prinsbj
prinsbjFlag for Netherlands

asked on

Need help to convert code from VBA (Access) to vb.net Visual Studio 2008

Hello,

Can somebody help me to convert this code to VB.net. In my Access code it works good but now I'm converting this app to VB.net

Thanks

Bart
Option Compare Database
Function AddWorkHours(Starttime As Date, wkHrs As Double) As Date
Dim Endtime As Date, iDays As Integer, wkMin As Double, iHrs As Double, iMin As Double, xTime As Date, endHrs As Date
endHrs = Format(TimeValue(#1/1/1900 5:00:00 PM#), "hh:nn:ss")
If VarType(Starttime) <> 7 Then
   AddWorkHours = Null
   Exit Function
End If
    xTime = Format(TimeValue(Starttime), "hh:nn:ss")
    If xTime < #8:30:00 AM# Then Starttime = DateValue(Starttime) & " " & #8:30:00 AM#
    If xTime > #5:00:00 PM# Then xTime = #5:00:00 PM#
If Weekday(Starttime) = vbFriday Then
    If Weekday(DateAdd("h", wkHrs, Starttime)) = vbSaturday _
        Or Format(DateAdd("h", wkHrs, Starttime), "hh:nn:ss") > "17:00:00" Then
    Starttime = DateAdd("d", 2, Starttime)
    End If
End If
wkMin = wkHrs * 60

    Select Case wkMin
        Case Is > 510
            iDays = wkMin \ 510
            wkMin = wkMin - (iDays * 510)
            Endtime = DateAdd("d", iDays, Starttime)
            If wkMin > DateDiff("n", xTime, endHrs) Then
                Endtime = DateValue(Endtime) + 1 & " " & #8:30:00 AM#
                wkMin = wkMin - DateDiff("n", xTime, endHrs)
                iHrs = wkMin \ 60: iMin = wkMin Mod 60
                Endtime = DateAdd("h", iHrs, Endtime)
                Endtime = DateAdd("n", iMin, Endtime)
                If Weekday(Endtime) = vbSaturday Then Endtime = DateAdd("d", 2, Endtime)
                Else
                iHrs = wkMin \ 60: iMin = wkMin Mod 60
                    Endtime = DateAdd("h", iHrs, Endtime)
                    Endtime = DateAdd("n", iMin, Endtime)
            End If
        Case Is < 510
            Endtime = Starttime
            If wkMin > DateDiff("n", xTime, endHrs) Then
                Endtime = DateValue(Endtime) + 1 & " " & #8:30:00 AM#
                wkMin = wkMin - DateDiff("n", xTime, endHrs)
                iHrs = wkMin \ 60: iMin = wkMin Mod 60
                Endtime = DateAdd("h", iHrs, Endtime)
                Endtime = DateAdd("n", iMin, Endtime)
                Else
                iHrs = wkMin \ 60: iMin = wkMin Mod 60
                    Endtime = DateAdd("h", iHrs, Endtime)
                    Endtime = DateAdd("n", iMin, Endtime)
            End If
        Case Is = 510
            Endtime = Starttime
            If wkMin > DateDiff("n", xTime, endHrs) Then
                Endtime = DateValue(Endtime) + 1 & " " & #8:30:00 AM#
                wkMin = wkMin - DateDiff("n", xTime, endHrs)
                iHrs = wkMin \ 60: iMin = wkMin Mod 60
                Endtime = DateAdd("h", iHrs, Endtime)
                Endtime = DateAdd("n", iMin, Endtime)
                Else
                iHrs = wkMin \ 60: iMin = wkMin Mod 60
                    Endtime = DateAdd("h", iHrs, Endtime)
                    Endtime = DateAdd("n", iMin, Endtime)
            End If
        
    End Select
AddWorkHours = Endtime
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Tuyau2poil
Tuyau2poil

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