-
K...Here's the code I have...
Code:
vntService = txtService.text
dtmTemp = Format(vntService, "dd,mm,yy")
If IsDate(dtmTemp) Then
vntNextService = DateAdd("m", 6, dtmTemp)
strNextService = vntNextService
strService = Str(dtmTemp)
Else
txtService holds a date value in the British format of dd/mm/yy. If a date such as 13/13/01 is entered, a message box will be displayed informing the user of this. However, if a date such as 12/13/01 is entered, which would be invalid under the British date system, the code I have, even without the "Format" line, converts the date to mm/dd/yy, which, although a valid date is now held in the variable, causes a later part of the program to work incorrectly.
If someone could tell me how to stop this automatic formatting without splitting up the date variable and analyzing each element, I would be extremely grateful!
BTW, changing the latter part of the program is not an option. I need this bit to work properly.
TIA!!!
-
<?>
Just a thought...
correct it first then format.
Code:
Private Sub Form_Load()
Dim x
x = 121301
If Val(Mid(x, 2, 2)) > 12 Then
MsgBox "wrong"
x = Mid(x, 3, 2) & Left(x, 2) & Right(x, 2)
MsgBox x
End If
End Sub
-
I think this was...
someone had this same problem before...
if you format it...you are 'fixing' it.
there is no way around it because if you check IsDate it will check if any date format works for it...
you will have to "pull it apart" and analyze it.
at least I think thats what it came down to. Since search is not working yet...cant find it!!!
:)
IMHO: It will prbably take less time to write a code to analyze it than to figure out how to make this way work.
-
HeSaidJoe...Beat me to the punch (once again)
but I think thats the best idea...
-
-
ok...one more idea...
Just for fun...
I tried this...
x = #13/12/2001#
MsgBox Month(x) & "/" & Day(x) & "/" & Year(x)
displays...
12/13/2001
x = #12/13/2001#
displays
12/13/2001
it fixes the date on its own! it find a value that is acceptable for a month and takes it...whether its in the 1st or second spot.
hmmm
it looks like you WILL have to pull it apart...
-
One last question, does VB 5 (which I'm using at college) support the "Split" functon, coz I can't find it in the help file.
-
no..its the Split2 something or other....
Again..no search..cant find it...but it is there...just a different function...
-
My little snippet..
Code:
Private Function GetLocalDateFormat() As Byte
'This Function Returns 0 if US date Format
'and 1 if British Date Format
Dim SampleDate As String
SampleDate = "1/2/2000"
GetLocalDateFormat = IIf(Month("1/2/200") = 2, 1, 0)
End Function
-
Thanks for all your help guys!
-
<?>
Code:
'VB5 Split Function
'split function for VB5 and under vb6 has the function
'posted originally by Aaron Young
Public Function Split2(ByVal sString As String, ByVal sSeparator As String) As Variant
Dim sParts() As String
Dim lParts As Long
Dim lPos As Long
lPos = InStr(sString, sSeparator)
While lPos
ReDim Preserve sParts(lParts)
sParts(lParts) = Left(sString, lPos - 1)
sString = Mid(sString, lPos + Len(sSeparator))
lPos = InStr(sString, sSeparator)
lParts = lParts + 1
Wend
If Len(sString) Then
ReDim Preserve sParts(lParts)
sParts(lParts) = sString
End If
Split2 = IIf(lParts, sParts, Array())
End Function
'Example:
Private Sub Form_Load()
Dim vLines As Variant
Dim lLine As Long
vLines = Split2("Line1,Line2,Line3", ",")
For lLine = 0 To UBound(vLines)
List1.AddItem vLines(lLine)
Next
End Sub