Consulting

Results 1 to 4 of 4

Thread: String length mismatch

  1. #1
    VBAX Newbie
    Joined
    Sep 2013
    Posts
    1
    Location

    String length mismatch

    Hi,

    I cannot figure out why my VBA is returning a result different to what I'm expecting.

    I have the following line of code:

    numDays = DateDiff("d", Now, LastTestDate)

    In debug mode the result is '-111'.

    However, when I try to get the length of 'numDays':
    strLen = Len(numDays)

    It returns the value of '2'.

    Can anyone help explain this please?

    Cheers,
    K.

  2. #2
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    what data types are you dealing with?
    Check data types, and drop them into a variant type variable if you need to read this.
    Setting your data inputs to variables will allow you to read the input data as well - and compare the numbers to your manual calcs.

    Also, do you need to use datediff? can you simply subtract one date from the other and take the integer result as your answer (truncate - don't round)
    regards
    Tim
    Remember: it is the second mouse that gets the cheese.....

  3. #3
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    without seeing your code, I am not sure of the reason for the difference in string length - but suspect it is due to what data type you are calculating
    Remember: it is the second mouse that gets the cheese.....

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Is the result correct ?

    numDays = DateDiff("d", date, LastTestDate)
    the same result

    numDays = date- LastTestDate

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •