?
Solved

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

Posted on 2011-03-06
1
Medium Priority
?
417 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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