Depths of my boredom...

# Thread: Depths of my boredom...

1. Senior Member
Join Date
Dec 1969
Posts
2,809

## Depths of my boredom...

Guys, have a look at this code and tell me if it could have been done easier. There&#039;s a post about 20 down or so that some guy wanted a function to return the number as a word. (4 as Four). I got bored and decided to try. I wrote this for up to the thousands place but it would be really easy to extrapolate it out pretty much as far as you want. The only thing that I didn&#039;t code for is zero. I&#039;m afraid to look at Bill W&#039;s example cuz he probably did it in 3 lines. Thanks! And my code is indented, they just don&#039;t show up when I cut and post so no yelling at me Doug!!<BR><BR>Function isNext(Num, checkNum)<BR> If Num = checkNum Then<BR> isNext = True<BR> Else<BR> isNext = False<BR> End If<BR>End Function<BR><BR>Function isSpecial(strTempNum)<BR> Select Case strTempNum<BR> Case "1"<BR> isSpecial = "One"<BR> Case "2"<BR> isSpecial = "Two"<BR> Case "3"<BR> isSpecial = "Three"<BR> Case "4"<BR> isSpecial = "Four"<BR> Case "5"<BR> isSpecial = "Five"<BR> Case "6"<BR> isSpecial = "Six"<BR> Case "7"<BR> isSpecial = "Seven"<BR> Case "8"<BR> isSpecial = "Eight"<BR> Case "9"<BR> isSpecial = "Nine"<BR> Case "10"<BR> isSpecial = "Ten"<BR> Case "11"<BR> isSpecial = "Eleven"<BR> Case "12"<BR> isSpecial = "Twelve"<BR> Case "13"<BR> isSpecial = "Thirteen"<BR> Case "14"<BR> isSpecial = "Fourteen"<BR> Case "15"<BR> isSpecial = "Fifteen"<BR> Case "16"<BR> isSpecial = "Sixteen"<BR> Case "17"<BR> isSpecial = "Seventeen"<BR> Case "18"<BR> isSpecial = "Eighteen"<BR> Case "19"<BR> isSpecial = "Nineteen"<BR> End Select<BR>End Function<BR><BR>Function ReturnNumber(varNumber)<BR> Dim strTemp, strLength, strPlace<BR> <BR> <BR> strTemp = varNumber<BR> strLength = trim(len(strTemp))<BR> <BR> Select Case strLength<BR> Case "1"<BR> ReturnNumber = isSpecial(strTemp)<BR> Case "2"<BR> if isNext(left(strTemp,1),"2") Then<BR> ReturnNumber = "Twenty " & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> else<BR> If isNext(left(strTemp,1),"0") Then<BR> strTemp = right(strTemp,1)<BR> End If<BR> ReturnNumber = isSpecial(strTemp)<BR> End If<BR> <BR> if isNext(left(strTemp,1),"3") Then<BR> ReturnNumber = "Thirty " & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> End If<BR> if isNext(left(strTemp,1),"4") Then<BR> ReturnNumber = "Forty " & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> End If<BR> if isNext(left(strTemp,1),"5") Then<BR> ReturnNumber = "Fifty " & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> End If<BR> if isNext(left(strTemp,1),"6") Then<BR> ReturnNumber = "Sixty " & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> End If<BR> if isNext(left(strTemp,1),"7") Then<BR> ReturnNumber = "Seventy " & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> End If<BR> if isNext(left(strTemp,1),"8") Then<BR> ReturnNumber = "Eighty " & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> End If<BR> if isNext(left(strTemp,1),"9") Then<BR> ReturnNumber = "Ninety " & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> End If<BR> Case "3"<BR> If left(strTemp,1) &#060;&#062; "0" Then<BR> ReturnNumber = isSpecial(left(strTemp,1)) & " Hundred " & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> Else<BR> ReturnNumber = isSpecial(left(strTemp,1)) & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> End If<BR> Case "4"<BR> If left(strTemp,1) &#060;&#062; "0" Then<BR> ReturnNumber = isSpecial(left(strTemp,1)) & " Thousand " & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> Else<BR> ReturnNumber = isSpecial(left(strTemp,1)) & ReturnNumber(right(strTemp, len(strTemp)-1))<BR> End If<BR> End Select <BR><BR><BR>End Function<BR><BR><BR>strNumber = ReturnNumber("0001")<BR><BR>Response.Write "number: " & strNumber

2. Senior Member
Join Date
Dec 1969
Posts
999

## RE: you betcha

http://www.clearviewdesign.com/NEWBIE/NumToWords.asp

3. Senior Member
Join Date
Dec 1969
Posts
2,809

## Ugh...

That&#039;s much better. I suck.

4. Senior Member
Join Date
Dec 1969
Posts
5,104

## Before posting..

Do a find and replace.<BR><BR>Replace all tabs with 4 or 5 spaces.<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
•