Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function findSwitch(theString As String, intStart As Integer) As Integer
Dim intCount As Integer
intCount = 1
Do
intCount = intCount + 1
Loop While IsNumeric(Mid(theString, intStart, 1)) = IsNumeric(Mid(theString, intStart + intCount, 1))
findSwitch = intCount
End Function
Public Sub parseString(theString As String)
Dim intSwitchStart As Integer
Dim intSwitchPos As Integer
Dim alpha1 As String
Dim num1 As Integer
Dim alpha2 As String
intSwitchStart = intSwitchPos + 1
intSwitchPos = findSwitch(theString, intSwitchStart)
alpha1 = Mid(theString, 1, intSwitchPos)
MsgBox alpha1
intSwitchStart = intSwitchPos + 1
intSwitchPos = findSwitch(theString, intSwitchStart)
num1 = Mid(theString, intSwitchStart, intSwitchPos)
MsgBox num1
intSwitchStart = intSwitchPos + 1
intSwitchPos = findSwitch(theString, intSwitchStart)
alpha2 = Mid(theString, intSwitchStart, intSwitchPos)
MsgBox alpha2
End Sub
[blue]Public Function SplitDat(Dat As String) As String
Dim Pack As String, strAlpha As String, Rpl As String
Dim curAlpha As Boolean, preAlpha As Boolean, x As Integer
Pack = Dat
For x = 2 To Len(Dat)
strAlpha = Mid(Dat, x - 1, 2)
preAlpha = IsNumeric(Mid(Dat, x - 1, 1))
curAlpha = IsNumeric(Mid(Dat, x, 1))
If preAlpha <> curAlpha Then
Rpl = Left(strAlpha, 1) & "," & Right(strAlpha, 1)
Pack = Replace(Pack, strAlpha, Rpl)
End If
Next
SplitDat = Pack
End Function[/blue]
[blue] Me!TextboxName = SplitDat("D22345B")[/blue]
Public Function SplitAlphaNumeric(theString As String) As Variant
Dim aVarArray() As Variant
Dim intSplits As Integer
Dim intIndex As Integer
Dim intSwitchStart As Integer
Dim intSwitchPos As Integer
ReDim aVarArray(countSwitches(theString))
intSwitchStart = 1
Do
intSplits = intSplits + 1
intSwitchStart = intSwitchStart + intSwitchPos
intSwitchPos = findSwitch(theString, intSwitchStart)
intIndex = intIndex + 1
aVarArray(intIndex) = Mid(theString, intSwitchStart, intSwitchPos)
MsgBox aVarArray(intIndex)
Loop Until intSwitchStart + intSwitchPos >= Len(theString)
SplitAlphaNumeric = aVarArray
End Function
Public Function countSwitches(theString As String) As Integer
Dim isChrNumeric As Boolean
Dim intcounter As Integer
countSwitches = 1
isChrNumeric = IsNumeric(Left(theString, 1))
For intcounter = 2 To Len(theString)
If Not (IsNumeric(Mid(theString, intcounter, 1)) = isChrNumeric) Then
countSwitches = countSwitches + 1
isChrNumeric = Not (isChrNumeric)
End If
Next intcounter
End Function
Public Function findSwitch(theString As String, intStart As Integer) As Integer
Dim intCount As Integer
intCount = 1
If Not (IsNumeric(Mid(theString, intStart, 1)) = IsNumeric(Mid(theString, intStart + 1, 1))) Then
intCount = 1
Else
Do
intCount = intCount + 1
Loop While IsNumeric(Mid(theString, intStart, 1)) = IsNumeric(Mid(theString, intStart + intCount, 1)) And Not ((intStart + intCount) > Len(theString))
End If
findSwitch = intCount
End Function
Public Sub test(theString As String)
Dim intcounter As Integer
Dim x() As Variant
x = SplitAlphaNumeric(theString)
For intcounter = 0 To UBound(x)
Debug.Print x(intcounter)
Next intcounter
End Sub
test("a1abc123qwer1234")
a
1
abc
123
qwer
1234
Option Explicit
Public Function getPartLength(theString As String, intStart As Integer) As Integer
'Find the length of the alphabetic or numeric part
Dim intCount As Integer
intCount = 1
If Not (IsNumeric(Mid(theString, intStart, 1)) = IsNumeric(Mid(theString, intStart + 1, 1))) Then
intCount = 1
Else
Do
intCount = intCount + 1
Loop While IsNumeric(Mid(theString, intStart, 1)) = IsNumeric(Mid(theString, intStart + intCount, 1)) And Not ((intStart + intCount) > Len(theString))
End If
getPartLength = intCount
End Function
Public Function SplitAlphaNumeric(theString As String) As Variant
Dim aVarArray() As Variant
Dim intSplits As Integer
Dim intIndex As Integer
Dim intSwitchStart As Integer
Dim intSwitchPos As Integer
ReDim aVarArray(countParts(theString) - 1)
intSwitchStart = 1
Do
intSplits = intSplits + 1
intSwitchStart = intSwitchStart + intSwitchPos
intSwitchPos = getPartLength(theString, intSwitchStart)
aVarArray(intIndex) = Mid(theString, intSwitchStart, intSwitchPos)
intIndex = intIndex + 1
Loop Until intSwitchStart + intSwitchPos > Len(theString)
SplitAlphaNumeric = aVarArray
End Function
Public Function countParts(theString As String) As Integer
Dim isChrNumeric As Boolean
Dim intcounter As Integer
countParts = 1
isChrNumeric = IsNumeric(Left(theString, 1))
For intcounter = 2 To Len(theString)
If Not (IsNumeric(Mid(theString, intcounter, 1)) = isChrNumeric) Then
countParts = countParts + 1
isChrNumeric = Not (isChrNumeric)
End If
Next intcounter
End Function
Public Sub test(theString As String)
Dim intcounter As Integer
Dim x() As Variant
x = SplitAlphaNumeric(theString)
For intcounter = 0 To UBound(x)
Debug.Print x(intcounter)
Next intcounter
End Sub
Public Function getPart(theString As String, intPartNumber As Integer) As String
Dim aVarArray() As Variant
aVarArray = SplitAlphaNumeric(theString)
If Not intPartNumber > UBound(aVarArray()) + 1 Then
getPart = aVarArray(intPartNumber - 1)
End If
End Function