Solved

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

Posted on 2011-03-06
1
412 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:prinsbj
1 Comment
 
LVL 4

Accepted Solution

by:
Tuyau2poil earned 500 total points
ID: 35048315
if you have visual studio , you can open vb6 project from VS interface and it will convert it for you.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question