Solved

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

Posted on 2011-03-06
1
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

687 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