• VB Function (XP/2K)

    • This topic has 2 replies, 3 voices, and was last updated 22 years ago.
    Author
    Topic
    #387175

    I have written the following function. The exact details are not important. (it gives a Jewish date in words for a civil date based on the site calmath that Hans sent me to)/
    The problem is that when I enter the variable dtdate and call the function it only works if I surround the variable with ## –
    If I call FCivil2HebFromDate (4/5/2003) I get the incorrect answer
    BUT if I call FCivil2HebFromDate (#4/5/2003#) it works. that variable is declared as a date.
    Should it need the extra # when I call it?
    Thanks

    Function FCivil2HebFromDate(dtdate As Date, Optional blaftersh3 As Boolean)

    Dim iyear As Integer
    Dim imonth As Integer
    Dim iday As Integer
    Dim blaftersh2 As Boolean

    blaftersh2 = blaftersh3

    iyear = DatePart(“yyyy”, dtdate)
    imonth = DatePart(“m”, dtdate)
    iday = DatePart(“d”, dtdate)
    FCivil2HebFromDate = Fcivil_hebrew(iyear, imonth, iday)

    End Function

    Viewing 1 reply thread
    Author
    Replies
    • #674736

      If you want to enter a literal value as argument, you must use the # signs, because otherwise the slashes / get interpreted as division: 4/5 = 0.8, and 4/5/2003 = 0.0003994.
      If you use a variable of type Date, or a text box or a field as argument, the function should interpret the contents as a date.

    • #675359

      Just an FYI, if you just want the day, month, and year of a date, then you can use their functions: Day, Month, Year, which return the numeric value of that part of a date. Just reduces the amount of code…..

      You could replace almost all of your code with the following:
      FCivil2HebFromDate = Fcivil_hebrew(Year(dtDate), Month(dtDate), Day(dtDate)

    Viewing 1 reply thread
    Reply To: VB Function (XP/2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: