This function counts up alphanumeric values. This is necessary, for example, for serial-number generation.
You can change the order and chars in your choice with the 'Values' variable.
You can change the order and chars in your choice with the 'Values' variable.
B4X:
'This function counts up alphanumeric values. This is necessary, for example,
'for serial-number generation.
'You can change the order and chars in your choice with the 'Values' variable.
'AlphaCountUp( "123AZ") > 123B0
Sub AlphaCountUp( StartValue As String) As String
'according to an idea by
'https://activevb.de/tipps/vb6tipps/tipp0522.html
Dim Values As String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim ReturnValue As String = ""
Dim NextUp As Boolean = True ' Starts with true = +1
StartValue = StartValue.Trim.ToUpperCase
' Check valid Input
For i=0 To StartValue.Length -1
If Values.IndexOf( StartValue.CharAt(i)) = -1 Then
LogDebug( "no valid StartValue "& i &" "& StartValue.CharAt(i))
Return ""
End If
Next
For i=StartValue.Length -1 To 0 Step -1
Dim c As String = StartValue.CharAt( i)
Dim p As Int = Values.IndexOf( c)
If NextUp Then
p = p +1
NextUp = False
End If
If p > Values.Length -1 Then
' like 109 -> 110
ReturnValue = Values.CharAt( 0) & ReturnValue
NextUp = True
Else
ReturnValue = Values.CharAt( p) & ReturnValue
End If
Next
' one digit more like 99 -> 100
If NextUp Then ReturnValue = Values.CharAt(1) & ReturnValue
' Log( TAB& StartValue)
' Log( TAB& ReturnValue)
Return ReturnValue
End Sub