Results 1 to 6 of 6
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919

    How can this be?


    I've traced the following code in debug a couple of times in disbelief. The function receives the string "3/6". With the split, UBound(Ar) is 1; Ar(0) = 3; Ar(1) = 6. The LastDay function receives Ar(0), which is 3, and returns 31, the last day of month March. Given those values, the function VDate should return 0, since 6 <= 31.

    Code:
    Private Function VDate(strMD As String) As Integer
    Dim LDOM As String
    
    Ar = Split(strMD, "/")
    LDOM = LastDay(Ar(0))
    
    VDate = 1
        If UBound(Ar) = 1 Then
            If Ar(0) >= 1 And Ar(0) <= 12 Then
                If Ar(1) >= 1 Then
                    If Ar(1) <= LDOM Then VDate = 0
                End If
            End If
        End If
    
    End Function

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Might it be doing a string comparison, particularly since you declared the variable as such?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Yes it "was". I had just changed the variables involved in the comparisons to integer and that cleared up the issue when your post came in.

    Here's the revised code.

    Code:
    Private Function VDate(strMD As String) As Integer
    Dim LDOM As Integer
    Dim mm As Integer
    Dim dd As Integer
    
    Ar = Split(strMD, "/")
    mm = Ar(0)
    dd = Ar(1)
    LDOM = LastDay(mm)
    
    VDate = 1
        If UBound(Ar) = 1 Then
            If mm >= 1 And mm <= 12 Then
                If dd >= 1 Then
                    If dd <= LDOM Then VDate = 0
                End If
            End If
        End If
    
    End Function

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Just noticed that the mm, dd and LDOM assignments needed to be deferred until the Ar dimension was verified.

    Code:
    Private Function VDate(strMD As String) As Integer
    Dim LDOM As Integer
    Dim mm As Integer
    Dim dd As Integer
    
    VDate = 1
    
    Ar = Split(strMD, "/")
        If UBound(Ar) = 1 Then
            mm = Ar(0)
            dd = Ar(1)
            LDOM = LastDay(mm)
            
            If mm >= 1 And mm <= 12 Then
                If dd >= 1 Then
                    If dd <= LDOM Then VDate = 0
                End If
            End If
        End If
    
    End Function

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You still have an undeclared variable, so must not have Option Explicit at the top. Unless it's declared elsewhere.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Ar is dim'd string and is global to the form's code module. And yes, I always code with Option Explicit enabled.

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums