|
-
Feb 18th, 2006, 09:20 AM
#1
Thread Starter
Lively Member
-
Feb 18th, 2006, 09:25 AM
#2
Re: string increment
VB Code:
Public Function IncrementString(ByVal sTxt As String, ByVal nIncrement As Long) As String
Dim sParts() As String
Dim nUpperIdx As Long
'Split the string into different parts, use / as the delimiter
sParts = Split(sTxt, "/")
'the part to increment is the last number
nUpperIdx = UBound(sParts)
'Check that this part is numeric
If IsNumeric(sParts(nUpperIdx)) Then
'increment this part with nIncrement
sParts(nUpperIdx) = [b]Format$(CLng(sParts(nUpperIdx)) + nIncrement, String(Len(sParts(nUpperIdx)), "0"))[/b]
End If
'Join the parts again and return the new string
IncrementString = Join(sParts, "/")
End Function
Please use [ vbcode ] and [ /vbcode ] tags (without the spaces) when you post source code.
-
Feb 18th, 2006, 09:48 AM
#3
Thread Starter
Lively Member
-
Feb 18th, 2006, 10:05 AM
#4
Thread Starter
Lively Member
Re: string increment
it will work for AI/WE/23---------->AI/WE/24
-
Feb 18th, 2006, 10:22 AM
#5
Re: string increment
I tried it with: AI/WE/001 -> AI/WE/002
-
Feb 18th, 2006, 10:31 AM
#6
Thread Starter
Lively Member
Re: string increment
but i reqired for both 001 and 23
-
Feb 18th, 2006, 10:38 AM
#7
Re: string increment
Yeah, it works for any number.
AI/WE/23 --> AI/WE/24
AI/WE/023 --> AI/WE/024
..and so on...
-
Feb 18th, 2006, 12:31 PM
#8
Thread Starter
Lively Member
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
|