Results 1 to 2 of 2

Thread: Val Function

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    28

    Val Function

    In Access 97 the Val Function returned only the numeric portion of an alphanumeric string (ABCD0001.tif) would return (0001)

    In Access 2003, 2000 format the same Val function stops at the first occurence of a character so the above example would return (0)

    If you don't know the length of your prefixes (ABCD or BG) but you do know your extention (.tif) how can you return only the numeric portion of the example? I know how to use left, mid & right functions but I would hate to have to run a loop checking the length of each prefix in a string.

    Any suggestions??

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Val Function

    sounds complicated, but
    VB Code:
    1. mystr = "abcd00123.tif"
    2. For i = 1 To Len(mystr)
    3.     If IsNumeric(Mid(mystr, i, 1)) Then Exit For
    4. Next
    5. myval = Val(Mid(mystr, i))

    val does not return leading zeros
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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