Re: Number problem
- From: Dr John Stockton <spam@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 22 Apr 2005 22:24:21 +0100
JRS: In article <#Y85WdxRFHA.3988@xxxxxxxxxxxxxxxxxxxx>, dated Fri, 22
Apr 2005 10:46:09, seen in news:microsoft.public.scripting.vbscript,
Lasse Edsvik <lasse@xxxxxxxxxx> posted :
>Im trying to create a function that returns a letter........
>
>The function gets and int......
>
>if x between 1 and 3 then letter = A
>if x between 4 and 6 then letter = B
>if x between 7 and 9 then letter = C
>
>is there some smart way to do this without all the if's?
The numbers between those numbers are 2, 5, and 8 (assuming UK English,
as you are a neighbour) - thus Chr(65+(x-2)/3).
OTOH, if "between" is to include the end values, then note that
for x = 1 to 9 : document.write Chr(65+(x-1)\3) : Next
-> AAABBBCCC
Note : the reverse of Chr() is Asc(); so 65 can be written more
obviously as Asc("A") .
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.
- References:
- Number problem
- From: Lasse Edsvik
- Number problem
- Prev by Date: Re: readLine method help
- Next by Date: Re: readLine method help
- Previous by thread: Re: Number problem
- Next by thread: Get folder properties
- Index(es):
Relevant Pages
|