Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regina REXX - Set the next letter

Status
Not open for further replies.

Xizor76

Technical User
Jul 9, 2008
5
DE
Hi,

I create files in batch (with Regina REXX) which begin with a certain letter (this year it is 'R'). Every year I must set the next letter manually (next year it is 'S'). How can I set the next letter automatically using Regina REXX? When I reach the letter 'Z' the next letter must be an 'A'.

I want to do this on the first day of the year at 4 a.m.

Thanks!
Xi
 
This sounds like what I call a 'cylindrical array', but in your case, the solution is easy:

The problem is that for any year you want to know "what's the prefix-letter for this year?" That's an easy question. Start with the string "ABC ... XYZ". Take the year and substract 1995 (the last year it was "A"), MOD-26 and add one ('1'):

2013 - 1995 = 18
18 + 1 = 19
Mod(19,26) = 19
Substr("ABC ... XYZ",19,1) = "S"

What's happening here is we are computing the position in the string where the prefix-letter can be found.

Why MOD-26? In 2021, you'll want an "A" again. 2021-1995=26; Mod(26,26)=0; 0+1=1; Substr("ABC ... XYZ",1,1)="A"

Ta-da!!! ;-)

Frank Clarke
--America's source for adverse opinions since 1943.
 
How do you get to Carnegie Hall? Practice, practice, practice! I did my first example wrong. It should be:

2013 - 1995 = 18
Mod(18,26) = 18
18 + 1 = 19
Substr("ABC ... XYZ",19,1) = "S"


Frank Clarke
--America's source for adverse opinions since 1943.
 
Hi Frank!

That was exactly what I was searching for! Thanks for that!

Xi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top