|
-
Jan 23rd, 2007, 12:00 PM
#1
Thread Starter
Junior Member
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??
-
Jan 26th, 2007, 06:37 AM
#2
Re: Val Function
sounds complicated, but
VB Code:
mystr = "abcd00123.tif"
For i = 1 To Len(mystr)
If IsNumeric(Mid(mystr, i, 1)) Then Exit For
Next
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|