Sherrie
11-05-2011, 12:09 AM
Hi all,
I was hoping someone could explain some bits of this code that I keep finding on here.
I've added some comments where I need help with understanding what their purpose is:
Function ArrangedDate(StrDateInput)
Dim StrFullDate As String
Dim StrYear As String
Dim StrMonthDay As String
Dim StrMonth As String
Dim StrDay As String
Dim StrDate As String
Dim RegX As Object
Set RegX = CreateObject("vbscript.regexp") (What is RegX for?)
If Not Left(StrDateInput, 2) = "10" And _ (What does this section do?)
Not Left(StrDateInput, 2) = "11" And _
Not Left(StrDateInput, 2) = "12" Then
StrDateInput = "0" & StrDateInput
End If
StrFullDate = Left(StrDateInput, 10)
If Right(StrFullDate, 1) = " " Then
StrFullDate = Left(StrDateInput, 9)
End If
StrYear = Right(StrFullDate, 4)
StrMonthDay = Replace(StrFullDate, "/" & StrYear, "")
StrMonth = Left(StrMonthDay, 2)
StrDay = Right(StrMonthDay, Len(StrMonthDay) - 3) (What is the -3?)
If Len(StrDay) = 1 Then
StrDay = "0" & StrDay
End If
StrDate = StrYear & "." & StrMonth & "." & StrDay
RegX.Pattern = "[\:\/\ ]"
RegX.IgnoreCase = True
RegX.Global = True
ArrangedDate = RegX.Replace(StrDate, "-")
ExitFunction:
Set RegX = Nothing
End Function
Thanks heaps for any help! :hi:
I was hoping someone could explain some bits of this code that I keep finding on here.
I've added some comments where I need help with understanding what their purpose is:
Function ArrangedDate(StrDateInput)
Dim StrFullDate As String
Dim StrYear As String
Dim StrMonthDay As String
Dim StrMonth As String
Dim StrDay As String
Dim StrDate As String
Dim RegX As Object
Set RegX = CreateObject("vbscript.regexp") (What is RegX for?)
If Not Left(StrDateInput, 2) = "10" And _ (What does this section do?)
Not Left(StrDateInput, 2) = "11" And _
Not Left(StrDateInput, 2) = "12" Then
StrDateInput = "0" & StrDateInput
End If
StrFullDate = Left(StrDateInput, 10)
If Right(StrFullDate, 1) = " " Then
StrFullDate = Left(StrDateInput, 9)
End If
StrYear = Right(StrFullDate, 4)
StrMonthDay = Replace(StrFullDate, "/" & StrYear, "")
StrMonth = Left(StrMonthDay, 2)
StrDay = Right(StrMonthDay, Len(StrMonthDay) - 3) (What is the -3?)
If Len(StrDay) = 1 Then
StrDay = "0" & StrDay
End If
StrDate = StrYear & "." & StrMonth & "." & StrDay
RegX.Pattern = "[\:\/\ ]"
RegX.IgnoreCase = True
RegX.Global = True
ArrangedDate = RegX.Replace(StrDate, "-")
ExitFunction:
Set RegX = Nothing
End Function
Thanks heaps for any help! :hi: