
Aphanumeric Counter...
I have a problem trying to solve this...<BR>I need a function to convert a given number to an alphanumeric number like this:<BR><BR>999 = AA999<BR>1035 = AB035<BR>26999 = AZ999<BR>27000 = BA000<BR> :<BR> :<BR> :<BR>max alphanueric number = ZZ999<BR><BR>It looks easy but it isn't<BR>This is a good exercise for all...<BR><BR>Any help are welcome....

is there any logic?
Or I'm stupid and can't find it. Can you explain how the conversion to the alphanummeric 'number' should go?

RE: Aphanumeric Counter...
> It looks easy but it isn't<BR><BR>No, it's trivial. <BR><BR>> This is a good exercise for all...<BR><BR>For all who want to help this student do his homework.<BR><BR>**************<BR><BR>Come on now, if you're going to ask for help with homework, at least ask honestly!<BR><BR>If this really is *NOT* homework, then explain what else it could possibly be for. The solution would take...ummm... Well, four lines if you wanted to write the code neatly. But it could all be done in one (kind of ugly) line if you really wanted to.<BR>

It's dead easy, Dutch...
Ignore the last 3 digits. They just stay there untouched.<BR><BR>Then the rest of the numberthat is, the number of thousandscycles from 0 to 25 (A to Z) for 26 times (prefix A to Z).<BR><BR>I don't want to give the four line (or one ugly line) solution here because I think this is a kid trying to get us to do his homework for him. It's probably question number 17 on his takehome examination.<BR><BR>HEY! I just noticed that is examples are wrong!!!<BR><BR>A=0, B=1, C=2, etc., up to Z=25, right?<BR><BR>So AA999 is 0*26000+0*1000+999 or 0999 okay?<BR><BR>But then AZ999 should be 0*26000+25*1000+999 or 25999 and he has it as 26999!<BR><BR>And then BA000 should be 1*26000+0*1000+000 or 26000 and he has it as 27000.<BR><BR>Tch!<BR><BR>Did the instructor screw up the quiz or did Chrisitian transcribe it wrong? Hmmm...<BR><BR>

Yes, I thought something like that, but
I (yes blame me) *assumed* his examples would be correct. Also I was just as sceptic as you were so I wanted to know *if* he could explain it to me.

Heh! And you know what...
...it isn't all *that* ugly as a oneline function. But probably only a handful fewer characters of typing than the fourline version.<BR><BR>

Good night!
Off to bed. You get to answer Christian if he comes back with some reason other than homework that sounds "real" to you.<BR><BR>See if you can do it a oneline function (well, except for the FUNCTION and END FUNCTION lines, of course), just for the fun of it.<BR><BR>

RE: It's dead easy, Dutch...
I’m working on hotel reservations system.. <BR>The function is to give the reservation code on an alphanueric format to be easier to remember. Instead of using the unique ID that the database assigns to each registration, I want to convert this on alphanumeric code.. <BR>It can be that the tiredness don’t permit me to think correctly, but what looks like a simple function, was converted after working in her during 3 hours in somewhat complicated, and why do i have to reinvent the wheel if perhaps someone in this forum already had to resolve some similar problem.. <BR><BR>It’s been a long time that I’m not a kid... (I’m 26 years old) but It’s very difficult for my explaing you my problem because my natural language is not english, is spanish.... <BR><BR>Thanks for your help...<BR>

Not so easy.......
I’m working on hotel reservations system.. <BR>The function is to give the reservation code on an alphanueric format to be easier to remember. Instead of using the unique ID that the database assigns to each registration, I want to convert this on alphanumeric code.. <BR>It can be that the tiredness don’t permit me to think correctly, but what looks like a simple function, was converted after working in her during 3 hours in somewhat complicated, and why do i have to reinvent the wheel if perhaps someone in this forum already had to resolve some similar problem.. <BR><BR>It’s been a long time that I’m not a kid... (I’m 26 years old) but It’s very difficult for my explaing you my problem because my natural language is not english, is spanish.... <BR><BR>Thanks for your help...<BR>

Okay...since it isn't homework...
0032 >> AA032<BR>1000 >> AB000<BR>2123 >> AC123<BR>25999 >> AZ999<BR>26000 >> BA000<BR>26111 >> BA111<BR>51999 >> BZ999<BR>52000 >> CA000<BR>etc.<BR><BR>The principle is simple:<BR>A=0, B=1, C=2, ... Z=25<BR><BR>And the two characters simply represent the first character multiplied by 26 and then added to the second one.<BR><BR>So CD, for example is ( ( C * 26 ) + D ) or ( ( 2 * 26 ) + 3 ) or 55. So 55123 would be CD123.<BR><BR><%<BR>Sub EncodeResNumber( num )<BR> ' to start, capture only the thousands<BR> c1 = num 1000 ' the operator does INTEGER division<BR> ' How many times does 26 go into c1, then?<BR> c2 = c1 26 <BR> ' And then adjust c1 to ignore multiples of 26<BR> c1 = c1 MOD 26<BR> ' now convert each of those to a character...<BR> ' ... by adding each to the numerical representation of "A"<BR> c1 = ASC("A") + c1<BR> c2 = ASC("A") + c2<BR> ' and change the numbers into characters...<BR> c1 = CHR( c1 )<BR> c2 = CHR( c2 )<BR> ' now we need the three righthand digits...<BR> ' we get them by doing string manipulation:<BR> r3 = CSTR( 1000 + num ) ' add 1000 to ensure leading zeroes...<BR> r3 = RIGHT( r3, 3 ) ' ... when we chop off last 3 characters<BR> ' and our final answer:<BR> EncodeResNumber = c2 & c1 & r3<BR>End Function<BR>%><BR><BR>That's the *REALLY* long version of the code. Here's the version I wrote first:<BR><BR><%<BR>Sub EncodeResNumber( num )<BR> c1 = num 1000 <BR> c2 = c1 26 <BR> c1 = c1 MOD 26<BR> EncodeResNumber = CHR(65+c2) & CHR(65+c1) & RIGHT( CSTR(1000+num), 3)<BR>End Function<BR>%><BR><BR>And, finally, here is the "one line" version (it uses 3 lines on the screen, to make it readable, but it's only one line of VBScript code.<BR><BR><%<BR>Sub EncodeResNumber( num )<BR> EncodeResNumber = CHR( 65 + (num26000) ) _<BR> & CHR( 65 + ( (num1000) MOD 26 ) ) _<BR> & RIGHT( CSTR(1000+num), 3)<BR>End Function<BR>%><BR><BR>Incidentally, your English is quite good! So good that you fooled me into thinking you were a young American student. So English is not the problem.<BR><BR>
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

