pr2-eugin
Super Moderator
- Local time
- Today, 15:30
- Joined
- Nov 30, 2011
- Messages
- 8,494
Howdy peeps,
This is not an urgent or pushing matter. I am just having a slow/boring day - so thought I would tease my brain. So trying something bizarre. This is what I thought I would do, a logical challenge - Get Sequence String based on position.
The String sequence is A, B, C, D.... Z, AA, AB, AC.... AZ, BA, BB, BC.. ZZ, AAA, AAB, AAC... ZZZ (you get the idea !)
Input : Number - (zero bound) example 5, 51
Output : String - example (for the input 5) F, (for the input 51) AZ
So I have two option (the very basic/lazy Case and Loop).
So testing,
Although I have a feeling, this could be solved by simple mathematical/arithmetic calculations. Anyone have alternatives?
This is not an urgent or pushing matter. I am just having a slow/boring day - so thought I would tease my brain. So trying something bizarre. This is what I thought I would do, a logical challenge - Get Sequence String based on position.
The String sequence is A, B, C, D.... Z, AA, AB, AC.... AZ, BA, BB, BC.. ZZ, AAA, AAB, AAC... ZZZ (you get the idea !)
Input : Number - (zero bound) example 5, 51
Output : String - example (for the input 5) F, (for the input 51) AZ
So I have two option (the very basic/lazy Case and Loop).
Code:
Public Function getStringSeq(tmpVar As Long) As String
Select Case tmpVar
Case Is <= 25
getStringSeq = Chr(tmpVar + 65)
Case 26 To 51
getStringSeq = Chr(65) & Chr(tmpVar + 65 - 26)
Case 52 To 77
getStringSeq = Chr(66) & Chr(tmpVar + 65 - 52)
Case 78 To 103
getStringSeq = Chr(67) & Chr(tmpVar + 65 - 78)
Case 104 To 129
getStringSeq = Chr(68) & Chr(tmpVar + 65 - 104)
Case 130 To 155
getStringSeq = Chr(69) & Chr(tmpVar + 65 - 130)
Case 156 To 181
getStringSeq = Chr(70) & Chr(tmpVar + 65 - 156)
Case 182 To 207
getStringSeq = Chr(71) & Chr(tmpVar + 65 - 182)
Case 208 To 233
getStringSeq = Chr(72) & Chr(tmpVar + 65 - 208)
Case 234 To 259
getStringSeq = Chr(73) & Chr(tmpVar + 65 - 234)
Case 260 To 285
getStringSeq = Chr(74) & Chr(tmpVar + 65 - 260)
Case 286 To 311
getStringSeq = Chr(75) & Chr(tmpVar + 65 - 286)
Case 312 To 337
getStringSeq = Chr(76) & Chr(tmpVar + 65 - 312)
Case 338 To 363
getStringSeq = Chr(77) & Chr(tmpVar + 65 - 338)
Case 364 To 389
getStringSeq = Chr(78) & Chr(tmpVar + 65 - 364)
Case 390 To 415
getStringSeq = Chr(79) & Chr(tmpVar + 65 - 390)
[COLOR=Green]'Case can go on and on and on.....[/COLOR]
End Select
End Function
Public Function getStringSeq2(tmpVar As Long) As String
Dim iCtr As Long, depthInt As Long
Dim preFix As String, midCtr As Long
Dim tmpStr As String, tickCtr As Long
Dim loopCtr As Long
depthInt = 1
For iCtr = 1 To tmpVar
[COLOR=Green]'Determine the Base 0-25 is A-Z.
'When it hits 26 and multiplies of 26. The sequence will increase the previous length.[/COLOR]
tickCtr = iCtr Mod 26
If tickCtr = 0 Then
loopCtr = loopCtr + 1
[COLOR=Green]'Get the number of depths it needs to go 1'st time it would be 2, second 3 etc.[/COLOR]
depthInt = depthInt + (iCtr Mod (26 * loopCtr))
[COLOR=Green]'Make sure the loop is not repeated until the next 26th factor.[/COLOR]
tickCtr = tickCtr + 1
preFix = vbNullString
For midCtr = 1 To depthInt
preFix = preFix & Chr(65 + loopCtr - midCtr)
Next
End If
tmpStr = preFix & Chr(65 + tickCtr)
Next
getStringSeq2 = tmpStr
End Function
Code:
? getStringSeq(401)
OL
? getStringSeq2(401)
OL