|
Visual Basic (VB and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Please read the DISCLAIMER.
Here is an INDEX to all the procedures.
You will probably need one copy of my GLOBAL DECLARATIONS.
Public Function strIncrementStringPortion(str1 As String, Optional iNcrement As Integer = 1) As String
' Procedure : strIncrementStringPortion
' Description: Increments the only digit portion of a character string.
' Copyright: Chris Greaves Inc.
' Inputs: A string.
' Returns: STRING
' Assumes: Only one string of digits in the data.
' Side Effects: None.
' Tested: By the calls shown below.
' Increment can be negative.
' Get what we assume is the only string of digits
Dim str2 As String
str2 = strOnly(str1, strcDigits)
' Determine its position in the source string
Dim i As Integer
i = InStr(1, str1, str2)
' Produce the incremented string
Dim str3 As String
str3 = Format(Val(str2) + iNcrement, String$(Len(str2), "0"))
' Produce the result from the leading, incremented and trailing portions of the string.
strIncrementStringPortion = Left$(str1, i - 1) & str3 & Right$(str1, Len(str1) - i - Len(str2) + 1)
'Sub TESTstrIncrementStringPortion()
'MsgBox strIncrementStringPortion("Indxr076")
'MsgBox strIncrementStringPortion("Indxr123ab")
'MsgBox strIncrementStringPortion(strIncrementStringPortion("Indxr123ab"))
'MsgBox strIncrementStringPortion("Indxr123ab", 2)
'MsgBox strIncrementStringPortion(strIncrementStringPortion("Indxr123ab", -3))
''MsgBox strIncrementStringPortion("Indxr12ff3ab")
'End Sub
End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Thursday, November 15, 2001 |