|
-
Jan 24th, 2001, 08:37 AM
#1
Thread Starter
Hyperactive Member
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!!!
-
Jan 24th, 2001, 08:52 AM
#2
_______
<?>
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
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jan 24th, 2001, 08:55 AM
#3
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.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 24th, 2001, 08:56 AM
#4
HeSaidJoe...Beat me to the punch (once again)
but I think thats the best idea...
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 24th, 2001, 09:04 AM
#5
Thread Starter
Hyperactive Member
-
Jan 24th, 2001, 09:06 AM
#6
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...
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 24th, 2001, 09:07 AM
#7
Thread Starter
Hyperactive Member
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.
-
Jan 24th, 2001, 09:12 AM
#8
no..its the Split2 something or other....
Again..no search..cant find it...but it is there...just a different function...
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 24th, 2001, 09:13 AM
#9
Addicted Member
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
If you can't pronounce my name, call me GURU 
-
Jan 24th, 2001, 09:16 AM
#10
Thread Starter
Hyperactive Member
Thanks for all your help guys!
-
Jan 24th, 2001, 09:17 AM
#11
_______
<?>
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
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|