2015/10/29 - Increase Numeric Part of Text in Microstation

Not long ago a posted my general approach for Replacing Text in Microstation.

I updated that macro and it now is able to increasing  the numeric part of any text in Microstation. The text could be plain text, a textnode or text encapsulated in a cell.

If you are interested in this macro, just contact me.

Here is a short description of what I did.

It demonstrates how easy it is to extend the macro with new replacing functions.

1) Write the vba code to increase the numeric part of a text in vba. To achieve that I searched the web for an appropriate example and came up with this. I modified it to meet the specs of the macro. Especially the return values for the new text and the status must the put in the global variable M_NEWTEXT and M_RETURN.

1) Write a piece of code that does it.

Public Function IncreaseNumericPartByOne() As Boolean

    Dim iCount As Integer, numberStart As Integer, numberEnd As Integer

    Dim sText As String, strNeg As String, strDec As String


    Dim vVal As String
    Dim increaseBy As Double
     
    increaseBy = 1
    sText = M_THETEXT

    strNeg = "-"

    strDec = "."


    numberStart = 0
    numberEnd = 0

    For iCount = 1 To Len(sText)

       vVal = Mid(sText, iCount, 1)
       If IsNumeric(vVal) Or (vVal = strNeg And numberStart = 0) Or vVal = strDec Then
         If numberStart = 0 Then
           'FIRST NUMBER CHAR
           numberStart = iCount
         End If
         numberEnd = iCount
       Else
         If numberStart = 0 Then
          'Number not yet started
         Else
          'Enb of Number reached
          Exit For
         End If
       End If
    Next iCount
   
    If numberStart = 0 Then
     'SORRY NO NUMBER - SET GLOBAL VARIABLE
     M_RETURN = False
    Else
     If numberEnd = 0 Then
      numberEnd = Len(sText)
     
     End If
     'BANG: A NUMBER - SET GLOBAL VARIABLES
     M_NEWTEXT = Left(sText, numberStart - 1) + CStr(CDbl(Mid(sText, numberStart, numberEnd - numberStart + 1)) + increaseBy) + Right(sText, Len(sText) - numberEnd)
     M_RETURN = True
    End If
    IncreaseNumericPartByOne = M_RETURN

End Function

2) Populate your code to make it available through the interface by just adding a line in the InitTextReplaceFunctions.

Public Function InitTextReplaceFunctions()
 Set M_TEXTREPLACEFUNCTIONS = New Collection


 M_TEXTREPLACEFUNCTIONS.Add "IncreaseByOneIfNumeric"
 M_TEXTREPLACEFUNCTIONS.Add "IncreaseNumericPartByOne"
 'your stuff
End Function

Done.