Results 1 to 11 of 11

Thread: Urgent! Help me please!

  1. #1

    Thread Starter
    Hyperactive Member CyberSurfer's Avatar
    Join Date
    Aug 2000
    Location
    Old London Town
    Posts
    425
    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!!!

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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"

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    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"

  5. #5

    Thread Starter
    Hyperactive Member CyberSurfer's Avatar
    Join Date
    Aug 2000
    Location
    Old London Town
    Posts
    425
    Thanks Guys!

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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"

  7. #7

    Thread Starter
    Hyperactive Member CyberSurfer's Avatar
    Join Date
    Aug 2000
    Location
    Old London Town
    Posts
    425
    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.

  8. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    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"

  9. #9
    Addicted Member
    Join Date
    Feb 2000
    Posts
    224
    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

  10. #10

    Thread Starter
    Hyperactive Member CyberSurfer's Avatar
    Join Date
    Aug 2000
    Location
    Old London Town
    Posts
    425
    Thanks for all your help guys!

  11. #11
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
  •  



Click Here to Expand Forum to Full Width