Solved

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

Posted on 2011-03-06
1
408 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
Comment Utility
if you have visual studio , you can open vb6 project from VS interface and it will convert it for you.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now