[futurebasic] Re: [FB] converting integers to letter triplets

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2005 : Group Archive : Group : All Groups

From: Jay Reeve <jayreeve@...>
Date: Sun, 12 Jun 2005 01:20:50 -0500
On Saturday, June 11, 2005, at 10:01  PM, Michael Evans wrote:

> My client, for reasons that are not entirely clear to me, wishes the 
> names of the sequentially numbered output folders to start with the 
> triplets AAA, AAB, AAC...etc. rather than the easier, if not trivial 
> triplets 001, 002, 003, etc.

Michael,

If you just need sequentially numbered (lettered?) names, here are 2 
bitty little fns that will each increment a 3-letter triplet string. 
You may pass them any string (of any length) starting with a 3-letter 
triplet (uppercase), and they will increment the triplet by 1. You 
never need to know the decimal equivalent--although you can still use 
the other fns to translate if you want it.

Should it ever get to "ZZZ", they will both  wrap around to "AAA", but 
the first one will also add a garbage byte to the end of the string. 
(The second will not.)

I made the second one unnecessarily cryptic just for fun. Some of the 
listers may enjoy trying to decipher it. I can send a more legible 
version if you want it. :-)

BTW, if underscores are missing, don't even try!

  e-e
  =J= a  y
   "


'~'A
'                             Runtime : RNTM Lite.INCL
'~'B

local fn incrementTriplet1(@t as ptr)
while t.3` == _"Z"
t.3` = _"A" : t --
wend
t.3` ++
end fn

local fn incrementTriplet2(@t as ptr)
select _pAtStRetch
case>t.3`:t.3` ++:_t=16705
case>t.2`:t.2` ++: t.3`=_t
case>t.1`:t.1` ++: t.2%=_t
case t.1`:t.1`=_t: t.2%=_t
end select
end fn

dim n$, r
n = "ZXW Folder"
for r = 1 to 300 step 2
print n,
fn incrementTriplet1(n)
print n,
fn incrementTriplet2(n)
next


--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@...