Hey all,
I have a program that needs to parse a two strings into a date type variable.
The first string contains the date in yyyymmdd format, whilst the second string is hh:nn format (well they should be, so I need error checking too).
Anyway here is the code:
Anyway, this code works perfectly on multiple machines I have tried it on (Office 97 on NT, Office 97 on win98, Office 2000 on Windows 2000, Office 2000 on Win NT, and XP on XP), however, when I send the database to a colleague, he gets an error in this code. I can't get him to identify the line of the error, as I can only send him mde files, but can guarentee it occurs on calles to MakeDate.
The only difference I can identify is that his system date settings are different (though the above works on machines with both dd/mm/yy format and mm/dd/yy), or that because he is running a Hebrew version of Windows 2000/Office 2000 that is somehow causing the problem.
Can anyone shed some light?
I have a program that needs to parse a two strings into a date type variable.
The first string contains the date in yyyymmdd format, whilst the second string is hh:nn format (well they should be, so I need error checking too).
Anyway here is the code:
Code:
Public Function MakeDate(strDate As String, strTime As String) As Date
Dim strMonth As String
If Not IsNumeric(strDate) Or Not (IsNumeric(Left(strTime, 2)) And IsNumeric(Right(strTime, 2))) Then
MsgBox "Date and Time aren't numeric strings"
Else
If Len(strDate) <> 8 Or Len(strTime) <> 5 Then
'Error
MsgBox "Lengths of Date or Time are wrong"
Else
strMonth = GetMonth(Int(Mid(strDate, 5, 2)))
MakeDate = DateValue(Right(strDate, 2) & " " & strMonth & " " & Left(strDate, 4))
MakeDate = DateAdd("h", Left(strTime, 2), MakeDate)
MakeDate = DateAdd("n", Right(strTime, 2), MakeDate)
End If
End If
End Function
Private Function GetMonth(intNumerical As Integer) As String
Select Case intNumerical
Case 1: GetMonth = "Jan"
Case 2: GetMonth = "Feb"
Case 3: GetMonth = "Mar"
Case 4: GetMonth = "Apr"
Case 5: GetMonth = "May"
Case 6: GetMonth = "Jun"
Case 7: GetMonth = "Jul"
Case 8: GetMonth = "Aug"
Case 9: GetMonth = "Sep"
Case 10: GetMonth = "Oct"
Case 11: GetMonth = "Nov"
Case 12: GetMonth = "Dec"
End Select
End Function
Anyway, this code works perfectly on multiple machines I have tried it on (Office 97 on NT, Office 97 on win98, Office 2000 on Windows 2000, Office 2000 on Win NT, and XP on XP), however, when I send the database to a colleague, he gets an error in this code. I can't get him to identify the line of the error, as I can only send him mde files, but can guarentee it occurs on calles to MakeDate.
The only difference I can identify is that his system date settings are different (though the above works on machines with both dd/mm/yy format and mm/dd/yy), or that because he is running a Hebrew version of Windows 2000/Office 2000 that is somehow causing the problem.
Can anyone shed some light?