Space In Variable Issue.

Intel / Family 15 model 6 steppin...
April 11, 2009 at 22:22:52
Specs: Windows XP, P4 / 2GB
Hello People,

With the help of some tips and tricks from the people of this forum I have managed to compile a little script which display text of the digit entered.

It seems to work fine but the only problem is the extra spaces that come out with the last variable echo'ed.

If you give 23001 or something as the input it gives the output as Twenty Three Thousand One.
I simply want to remove the extra spaces between Thousand and One.

Thank You.


Here is the code,

@echo off
@cls
set last1=
set last2=
set last3=
set last4=
set last5=
set last6=
set last7=
set last8=
set last9=

set spell1=
set spell2=
set spell3=
set spell4=
set spell5=
set spell6=
set spell7=
set spell8=
set spell9=
set len=
set spell21=
set spell45=
set spell76=
set spell98=
set bln=
set /p gd=Digit:
if %gd%==0 echo Zero && GOTO end
set /a ans=%gd% * 1
if not %ans%==%gd% echo Incorrect Input && GOTO end
set dg=%gd%
:loop
if defined gd (
set /a len+=1
set gd=%gd:~1%
goto loop
)

if %len%==10 GOTO d10
if %len%==9 GOTO d9
if %len%==8 GOTO d8
if %len%==7 GOTO d7
if %len%==6 GOTO d6
if %len%==5 GOTO d5
if %len%==4 GOTO d4
if %len%==3 GOTO d3
if %len%==2 GOTO d2
if %len%==1 GOTO d1

:d10
set ls10=%dg:~-10%
set last10=%ls10:~0,1%
if %last10%==1 set spell10=One
if %last10%==2 set spell10=Two
if %last10%==3 set spell10=Three
if %last10%==4 set spell10=Four
if %last10%==5 set spell10=Five
if %last10%==6 set spell10=Six
if %last10%==7 set spell10=Seven
if %last10%==8 set spell10=Eight
if %last10%==9 set spell10=Nine
if %last10%==0 set spell10=
set bln=Billion

:d9
set ls9=%dg:~-9%
set last9=%ls9:~0,1%
if %last9%==2 set spell9=Twenty
if %last9%==3 set spell9=Thirty
if %last9%==4 set spell9=Forty
if %last9%==5 set spell9=Fifty
if %last9%==6 set spell9=Sixty
if %last9%==7 set spell9=Seventy
if %last9%==8 set spell9=Eighty
if %last9%==9 set spell9=Ninety
if %last9%==0 set spell9=
:d8
set ls8=%dg:~-8%
set last8=%ls8:~0,1%
if %last8%==1 set spell8=One
if %last8%==2 set spell8=Two
if %last8%==3 set spell8=Three
if %last8%==4 set spell8=Four
if %last8%==5 set spell8=Five
if %last8%==6 set spell8=Six
if %last8%==7 set spell8=Seven
if %last8%==8 set spell8=Eight
if %last8%==9 set spell8=Nine
if %last8%==0 set spell8=

if %len%==8 GOTO d7
if %last9%==1 (if %last8%==0 set spell98=Ten)
if %last9%==1 (if %last8%==1 set spell98=Eleven)
if %last9%==1 (if %last8%==2 set spell98=Twelve)
if %last9%==1 (if %last8%==3 set spell98=Thirteen)
if %last9%==1 (if %last8%==4 set spell98=Fourteen)
if %last9%==1 (if %last8%==5 set spell98=Fifteen)
if %last9%==1 (if %last8%==6 set spell98=Sixteen)
if %last9%==1 (if %last8%==7 set spell98=Seventeen)
if %last9%==1 (if %last8%==8 set spell98=Eighteen)
if %last9%==1 (if %last8%==9 set spell98=Nineteen)
if %last8%==0 (if %last9%==0 set crr= ELSE set crr=Crore) ELSE set crr=Crore
if not %last9%==1 set spell98=%spell9% %spell8%

:d7
set ls7=%dg:~-7%
set last7=%ls7:~0,1%
if %last7%==2 set spell7=Twenty
if %last7%==3 set spell7=Thirty
if %last7%==4 set spell7=Forty
if %last7%==5 set spell7=Fifty
if %last7%==6 set spell7=Sixty
if %last7%==7 set spell7=Seventy
if %last7%==8 set spell7=Eighty
if %last7%==9 set spell7=Ninety
if %last7%==0 set spell7=

:d6
set ls6=%dg:~-6%
set last6=%ls6:~0,1%
if %last6%==1 set spell6=One
if %last6%==2 set spell6=Two
if %last6%==3 set spell6=Three
if %last6%==4 set spell6=Four
if %last6%==5 set spell6=Five
if %last6%==6 set spell6=Six
if %last6%==7 set spell6=Seven
if %last6%==8 set spell6=Eight
if %last6%==9 set spell6=Nine
if %last6%==0 set spell6=

if %len%==6 GOTO d5
if %last7%==1 (if %last6%==0 set spell76=Ten)
if %last7%==1 (if %last6%==1 set spell76=Eleven)
if %last7%==1 (if %last6%==2 set spell76=Twelve)
if %last7%==1 (if %last6%==3 set spell76=Thirteen)
if %last7%==1 (if %last6%==4 set spell76=Fourteen)
if %last7%==1 (if %last6%==5 set spell76=Fifteen)
if %last7%==1 (if %last6%==6 set spell76=Sixteen)
if %last7%==1 (if %last6%==7 set spell76=Seventeen)
if %last7%==1 (if %last6%==8 set spell76=Eighteen)
if %last7%==1 (if %last6%==9 set spell76=Nineteen)
if %last6%==0 (if %last7%==0 set lac= ELSE set lac=Lac) ELSE set lac=Lac
if not %last7%==1 set spell76=%spell7% %spell6%

:d5
set ls5=%dg:~-5%
set last5=%ls5:~0,1%
if %last5%==2 set spell5=Twenty
if %last5%==3 set spell5=Thirty
if %last5%==4 set spell5=Forty
if %last5%==5 set spell5=Fifty
if %last5%==6 set spell5=Sixty
if %last5%==7 set spell5=Seventy
if %last5%==8 set spell5=Eighty
if %last5%==9 set spell5=Ninety
if %last5%==0 set spell5=

:d4
set ls4=%dg:~-4%
set last4=%ls4:~0,1%
if %last4%==1 set spell4=One
if %last4%==2 set spell4=Two
if %last4%==3 set spell4=Three
if %last4%==4 set spell4=Four
if %last4%==5 set spell4=Five
if %last4%==6 set spell4=Six
if %last4%==7 set spell4=Seven
if %last4%==8 set spell4=Eight
if %last4%==9 set spell4=Nine
if %last4%==0 set spell4=

if %len%==4 GOTO d3

if %last5%==1 (if %last4%==0 set spell54=Ten)
if %last5%==1 (if %last4%==1 set spell54=Eleven)
if %last5%==1 (if %last4%==2 set spell54=Twelve)
if %last5%==1 (if %last4%==3 set spell54=Thirteen)
if %last5%==1 (if %last4%==4 set spell54=Fourteen)
if %last5%==1 (if %last4%==5 set spell54=Fifteen)
if %last5%==1 (if %last4%==6 set spell54=Sixteen)
if %last5%==1 (if %last4%==7 set spell54=Seventeen)
if %last5%==1 (if %last4%==8 set spell54=Eighteen)
if %last5%==1 (if %last4%==9 set spell54=Nineteen)
if %last4%==0 (if %last5%==0 set thn= ELSE set thn=Thousand) ELSE set thn=Thousand
if not %last5%==1 set spell54=%spell5% %spell4%

:d3
set ls3=%dg:~-3%
set last3=%ls3:~0,1%
if %last3%==1 set spell3=One
if %last3%==2 set spell3=Two
if %last3%==3 set spell3=Three
if %last3%==4 set spell3=Four
if %last3%==5 set spell3=Five
if %last3%==6 set spell3=Six
if %last3%==7 set spell3=Seven
if %last3%==8 set spell3=Eight
if %last3%==9 set spell3=Nine
if %last3%==0 set spell3=
if %last3%==0 (set hnd= ) ELSE (set hnd=Hundred)

:d2
set ls2=%dg:~-2%
set last2=%ls2:~0,1%
if %last2%==2 set spell2=Twenty
if %last2%==3 set spell2=Thirty
if %last2%==4 set spell2=Forty
if %last2%==5 set spell2=Fifty
if %last2%==6 set spell2=Sixty
if %last2%==7 set spell2=Seventy
if %last2%==8 set spell2=Eighty
if %last2%==9 set spell2=Ninety
if %last2%==0 set spell2=

:d1
set last1=%dg:~-1%
if %last1%==1 set spell1=One
if %last1%==2 set spell1=Two
if %last1%==3 set spell1=Three
if %last1%==4 set spell1=Four
if %last1%==5 set spell1=Five
if %last1%==6 set spell1=Six
if %last1%==7 set spell1=Seven
if %last1%==8 set spell1=Eight
if %last1%==9 set spell1=Nine
if %last1%==0 set spell1=
if %len%==1 GOTO dn

if %last2%==1 (if %last1%==0 set spell21=Ten)
if %last2%==1 (if %last1%==1 set spell21=Eleven)
if %last2%==1 (if %last1%==2 set spell21=Twelve)
if %last2%==1 (if %last1%==3 set spell21=Thirteen)
if %last2%==1 (if %last1%==4 set spell21=Fourteen)
if %last2%==1 (if %last1%==5 set spell21=Fifteen)
if %last2%==1 (if %last1%==6 set spell21=Sixteen)
if %last2%==1 (if %last1%==7 set spell21=Seventeen)
if %last2%==1 (if %last1%==8 set spell21=Eighteen)
if %last2%==1 (if %last1%==9 set spell21=Nineteen)
if not %last2%==1 set spell21=%spell2% %spell1%

:dn

echo.
echo.

if %len%==10 echo %spell10% %bln% %spell98% %crr% %spell76% %lac% %spell54% %thn% %spell3% %hnd% %spell21%
if %len%==9 echo %spell98% %crr% %spell76% %lac% %spell54% %thn% %spell3% %hnd% %spell21%
if %len%==8 echo %spell8% %crr% %spell76% %lac% %spell54% %thn% %spell3% %hnd% %spell21%
if %len%==7 echo %spell76% %lac% %spell54% %thn% %spell3% %hnd% %spell21%
if %len%==6 echo %spell6% %lac% %spell54% %thn% %spell3% %hnd% %spell21%
if %len%==5 echo %spell54% %thn% %spell3% %hnd% %spell21%
if %len%==4 echo %spell4% %thn% %spell3% %hnd% %spell21%
if %len%==3 echo %spell3% %hnd% %spell21%
if %len%==2 echo %spell21%
if %len%==1 echo %spell1%

:end


See More: Space In Variable Issue.

Report •


#1
April 11, 2009 at 22:52:54
This line is one of you problems, but there may be more:

if not %last2%==1 set spell21=%spell2% %spell1%

%spell2% isn't defined so spell21 is being set to <space>%spell1%.


Report •

#2
April 11, 2009 at 23:01:57
I think that shouldn't be the case because we have
if %len%==1 GOTO dn
so if last2 is not defined spell2 is not defined so it jumps to dn right away.

Report •

#3
April 12, 2009 at 00:52:28
That came from a practical test, edit in "set spell21" either side of the line mentioned above to reproduce my test.

I'll have another look at your script later, at the moment I don't feel like pouring over it so closely.


Report •

Related Solutions

#4
April 12, 2009 at 00:58:59
Thanks that you showed me this line:
spell21=%spell2% %spell1%

It gave me a silly idea. I trailed each word with a space and removed the space from the final echo but unfortunately it still gives blank spaces if there are 0's in the input :(

Here is the changed one,

@echo off
@cls
set last1=
set last2=
set last3=
set last4=
set last5=
set last6=
set last7=
set last8=
set last9=

set spell1=
set spell2=
set spell3=
set spell4=
set spell5=
set spell6=
set spell7=
set spell8=
set spell9=
set len=
set spell21=
set spell45=
set spell76=
set spell98=
set bln=
set lac=
set crr=
set /p gd=Digit:
if %gd%==0 echo Zero && GOTO end
set /a ans=%gd% * 1
if not %ans%==%gd% echo Incorrect Input && GOTO end
set dg=%gd%
:loop
if defined gd (
set /a len+=1
set gd=%gd:~1%
goto loop
)

if %len%==10 GOTO d10
if %len%==9 GOTO d9
if %len%==8 GOTO d8
if %len%==7 GOTO d7
if %len%==6 GOTO d6
if %len%==5 GOTO d5
if %len%==4 GOTO d4
if %len%==3 GOTO d3
if %len%==2 GOTO d2
if %len%==1 GOTO d1

:d10
set ls10=%dg:~-10%
set last10=%ls10:~0,1%
if %last10%==1 set spell10=One
if %last10%==2 set spell10=Two
if %last10%==3 set spell10=Three
if %last10%==4 set spell10=Four
if %last10%==5 set spell10=Five
if %last10%==6 set spell10=Six
if %last10%==7 set spell10=Seven
if %last10%==8 set spell10=Eight
if %last10%==9 set spell10=Nine
if %last10%==0 set spell10=
set bln=Billion

:d9
set ls9=%dg:~-9%
set last9=%ls9:~0,1%
if %last9%==2 set spell9=Twenty
if %last9%==3 set spell9=Thirty
if %last9%==4 set spell9=Forty
if %last9%==5 set spell9=Fifty
if %last9%==6 set spell9=Sixty
if %last9%==7 set spell9=Seventy
if %last9%==8 set spell9=Eighty
if %last9%==9 set spell9=Ninety
if %last9%==0 set spell9=
:d8
set ls8=%dg:~-8%
set last8=%ls8:~0,1%
if %last8%==1 set spell8=One
if %last8%==2 set spell8=Two
if %last8%==3 set spell8=Three
if %last8%==4 set spell8=Four
if %last8%==5 set spell8=Five
if %last8%==6 set spell8=Six
if %last8%==7 set spell8=Seven
if %last8%==8 set spell8=Eight
if %last8%==9 set spell8=Nine
if %last8%==0 set spell8=

if %len%==8 (set crr=Crore ) && GOTO d7
if %last9%==1 (if %last8%==0 set spell98=Ten )
if %last9%==1 (if %last8%==1 set spell98=Eleven )
if %last9%==1 (if %last8%==2 set spell98=Twelve )
if %last9%==1 (if %last8%==3 set spell98=Thirteen )
if %last9%==1 (if %last8%==4 set spell98=Fourteen )
if %last9%==1 (if %last8%==5 set spell98=Fifteen )
if %last9%==1 (if %last8%==6 set spell98=Sixteen )
if %last9%==1 (if %last8%==7 set spell98=Seventeen )
if %last9%==1 (if %last8%==8 set spell98=Eighteen )
if %last9%==1 (if %last8%==9 set spell98=Nineteen )
if %last8%==0 (if %last9%==0 (set crr= ) ELSE (set crr=Crore )) ELSE (set crr=Crore )
if not %last9%==1 set spell98=%spell9%%spell8%

:d7
set ls7=%dg:~-7%
set last7=%ls7:~0,1%
if %last7%==2 set spell7=Twenty
if %last7%==3 set spell7=Thirty
if %last7%==4 set spell7=Forty
if %last7%==5 set spell7=Fifty
if %last7%==6 set spell7=Sixty
if %last7%==7 set spell7=Seventy
if %last7%==8 set spell7=Eighty
if %last7%==9 set spell7=Ninety
if %last7%==0 set spell7=

:d6
set ls6=%dg:~-6%
set last6=%ls6:~0,1%
if %last6%==1 set spell6=One
if %last6%==2 set spell6=Two
if %last6%==3 set spell6=Three
if %last6%==4 set spell6=Four
if %last6%==5 set spell6=Five
if %last6%==6 set spell6=Six
if %last6%==7 set spell6=Seven
if %last6%==8 set spell6=Eight
if %last6%==9 set spell6=Nine
if %last6%==0 set spell6=

if %len%==6 (set lac=Lac ) && GOTO d5
if %last7%==1 (if %last6%==0 set spell76=Ten )
if %last7%==1 (if %last6%==1 set spell76=Eleven )
if %last7%==1 (if %last6%==2 set spell76=Twelve )
if %last7%==1 (if %last6%==3 set spell76=Thirteen )
if %last7%==1 (if %last6%==4 set spell76=Fourteen )
if %last7%==1 (if %last6%==5 set spell76=Fifteen )
if %last7%==1 (if %last6%==6 set spell76=Sixteen )
if %last7%==1 (if %last6%==7 set spell76=Seventeen )
if %last7%==1 (if %last6%==8 set spell76=Eighteen )
if %last7%==1 (if %last6%==9 set spell76=Nineteen )
if %last6%==0 (if %last7%==0 (set lac= ) ELSE (set lac=Lac )) ELSE (set lac=Lac )
if not %last7%==1 set spell76=%spell7%%spell6%

:d5
set ls5=%dg:~-5%
set last5=%ls5:~0,1%
if %last5%==2 set spell5=Twenty
if %last5%==3 set spell5=Thirty
if %last5%==4 set spell5=Forty
if %last5%==5 set spell5=Fifty
if %last5%==6 set spell5=Sixty
if %last5%==7 set spell5=Seventy
if %last5%==8 set spell5=Eighty
if %last5%==9 set spell5=Ninety
if %last5%==0 set spell5=

:d4
set ls4=%dg:~-4%
set last4=%ls4:~0,1%
if %last4%==1 set spell4=One
if %last4%==2 set spell4=Two
if %last4%==3 set spell4=Three
if %last4%==4 set spell4=Four
if %last4%==5 set spell4=Five
if %last4%==6 set spell4=Six
if %last4%==7 set spell4=Seven
if %last4%==8 set spell4=Eight
if %last4%==9 set spell4=Nine
if %last4%==0 set spell4=

if %len%==4 (set thn=Thousand ) && GOTO d3

if %last5%==1 (if %last4%==0 set spell54=Ten )
if %last5%==1 (if %last4%==1 set spell54=Eleven )
if %last5%==1 (if %last4%==2 set spell54=Twelve )
if %last5%==1 (if %last4%==3 set spell54=Thirteen )
if %last5%==1 (if %last4%==4 set spell54=Fourteen )
if %last5%==1 (if %last4%==5 set spell54=Fifteen )
if %last5%==1 (if %last4%==6 set spell54=Sixteen )
if %last5%==1 (if %last4%==7 set spell54=Seventeen )
if %last5%==1 (if %last4%==8 set spell54=Eighteen )
if %last5%==1 (if %last4%==9 set spell54=Nineteen )
if %last4%==0 (if %last5%==0 (set thn= ) ELSE (set thn=Thousand )) ELSE (set thn=Thousand )
if not %last5%==1 set spell54=%spell5%%spell4%

:d3
set ls3=%dg:~-3%
set last3=%ls3:~0,1%
if %last3%==1 set spell3=One
if %last3%==2 set spell3=Two
if %last3%==3 set spell3=Three
if %last3%==4 set spell3=Four
if %last3%==5 set spell3=Five
if %last3%==6 set spell3=Six
if %last3%==7 set spell3=Seven
if %last3%==8 set spell3=Eight
if %last3%==9 set spell3=Nine
if %last3%==0 set spell3=
if %last3%==0 (set hnd= ) ELSE (set hnd=Hundred )

:d2
set ls2=%dg:~-2%
set last2=%ls2:~0,1%
if %last2%==2 set spell2=Twenty
if %last2%==3 set spell2=Thirty
if %last2%==4 set spell2=Forty
if %last2%==5 set spell2=Fifty
if %last2%==6 set spell2=Sixty
if %last2%==7 set spell2=Seventy
if %last2%==8 set spell2=Eighty
if %last2%==9 set spell2=Ninety
if %last2%==0 set spell2=

:d1
set last1=%dg:~-1%
if %last1%==1 set spell1=One
if %last1%==2 set spell1=Two
if %last1%==3 set spell1=Three
if %last1%==4 set spell1=Four
if %last1%==5 set spell1=Five
if %last1%==6 set spell1=Six
if %last1%==7 set spell1=Seven
if %last1%==8 set spell1=Eight
if %last1%==9 set spell1=Nine
if %last1%==0 set spell1=
if %len%==1 GOTO dn

if %last2%==1 (if %last1%==0 set spell21=Ten )
if %last2%==1 (if %last1%==1 set spell21=Eleven )
if %last2%==1 (if %last1%==2 set spell21=Twelve )
if %last2%==1 (if %last1%==3 set spell21=Thirteen )
if %last2%==1 (if %last1%==4 set spell21=Fourteen )
if %last2%==1 (if %last1%==5 set spell21=Fifteen )
if %last2%==1 (if %last1%==6 set spell21=Sixteen )
if %last2%==1 (if %last1%==7 set spell21=Seventeen )
if %last2%==1 (if %last1%==8 set spell21=Eighteen )
if %last2%==1 (if %last1%==9 set spell21=Nineteen )
if not %last2%==1 set spell21=%spell2%%spell1%

:dn

echo.
echo.

if %len%==10 echo %spell10%%bln%%spell98%%crr%%spell76%%lac%%spell54%%thn%%spell3%%hnd%%spell21%
if %len%==9 echo %spell98%%crr%%spell76%%lac%%spell54%%thn%%spell3%%hnd%%spell21%
if %len%==8 echo %spell8%%crr%%spell76%%lac%%spell54%%thn%%spell3%%hnd%%spell21%
if %len%==7 echo %spell76%%lac%%spell54%%thn%%spell3%%hnd%%spell21%
if %len%==6 echo %spell6%%lac%%spell54%%thn%%spell3%%hnd%%spell21%
if %len%==5 echo %spell54%%thn%%spell3%%hnd%%spell21%
if %len%==4 echo %spell4%%thn%%spell3%%hnd%%spell21%
if %len%==3 echo %spell3%%hnd%%spell21%
if %len%==2 echo %spell21%
if %len%==1 echo %spell1%

:end


Report •

#5
April 12, 2009 at 06:11:24
I extended on your idea(you almost had it!) the blank spaces you were getting from you script above were from (set hnd= ) it should be undefined. I extended the trailing spaces to encompass all of the numbers.

There are lots of optimisations that could be done to this script, but I will leave that to you....

@echo off
@cls
set last1=
set last2=
set last3=
set last4=
set last5=
set last6=
set last7=
set last8=
set last9=

set spell1=
set spell2=
set spell3=
set spell4=
set spell5=
set spell6=
set spell7=
set spell8=
set spell9=
set len=
set spell21=
set spell45=
set spell76=
set spell98=
set bln=
set lac=
set crr=
set /p gd=Digit:
if %gd%==0 echo Zero && GOTO end
set /a ans=%gd% * 1
if not %ans%==%gd% echo Incorrect Input && GOTO end
set dg=%gd%
:loop
if defined gd (
set /a len+=1
set gd=%gd:~1%
goto loop
)

if %len%==10 GOTO d10
if %len%==9 GOTO d9
if %len%==8 GOTO d8
if %len%==7 GOTO d7
if %len%==6 GOTO d6
if %len%==5 GOTO d5
if %len%==4 GOTO d4
if %len%==3 GOTO d3
if %len%==2 GOTO d2
if %len%==1 GOTO d1

:d10
set ls10=%dg:~-10%
set last10=%ls10:~0,1%
if %last10%==1 set spell10=One 
if %last10%==2 set spell10=Two 
if %last10%==3 set spell10=Three 
if %last10%==4 set spell10=Four 
if %last10%==5 set spell10=Five 
if %last10%==6 set spell10=Six 
if %last10%==7 set spell10=Seven 
if %last10%==8 set spell10=Eight 
if %last10%==9 set spell10=Nine 
if %last10%==0 set spell10=
set bln=Billion 

:d9
set ls9=%dg:~-9%
set last9=%ls9:~0,1%
if %last9%==2 set spell9=Twenty 
if %last9%==3 set spell9=Thirty 
if %last9%==4 set spell9=Forty 
if %last9%==5 set spell9=Fifty 
if %last9%==6 set spell9=Sixty 
if %last9%==7 set spell9=Seventy 
if %last9%==8 set spell9=Eighty 
if %last9%==9 set spell9=Ninety 
if %last9%==0 set spell9=
:d8
set ls8=%dg:~-8%
set last8=%ls8:~0,1%
if %last8%==1 set spell8=One 
if %last8%==2 set spell8=Two 
if %last8%==3 set spell8=Three 
if %last8%==4 set spell8=Four 
if %last8%==5 set spell8=Five 
if %last8%==6 set spell8=Six 
if %last8%==7 set spell8=Seven 
if %last8%==8 set spell8=Eight 
if %last8%==9 set spell8=Nine 
if %last8%==0 set spell8=

if %len%==8 (set crr=Crore ) && GOTO d7
if %last9%==1 (if %last8%==0 set spell98=Ten )
if %last9%==1 (if %last8%==1 set spell98=Eleven )
if %last9%==1 (if %last8%==2 set spell98=Twelve )
if %last9%==1 (if %last8%==3 set spell98=Thirteen )
if %last9%==1 (if %last8%==4 set spell98=Fourteen )
if %last9%==1 (if %last8%==5 set spell98=Fifteen )
if %last9%==1 (if %last8%==6 set spell98=Sixteen )
if %last9%==1 (if %last8%==7 set spell98=Seventeen )
if %last9%==1 (if %last8%==8 set spell98=Eighteen )
if %last9%==1 (if %last8%==9 set spell98=Nineteen )
if %last8%==0 (if %last9%==0 (set crr=) ELSE (set crr=Crore )) ELSE (set crr=Crore )
if not %last9%==1 set spell98=%spell9%%spell8%

:d7
set ls7=%dg:~-7%
set last7=%ls7:~0,1%
if %last7%==2 set spell7=Twenty 
if %last7%==3 set spell7=Thirty 
if %last7%==4 set spell7=Forty 
if %last7%==5 set spell7=Fifty 
if %last7%==6 set spell7=Sixty 
if %last7%==7 set spell7=Seventy 
if %last7%==8 set spell7=Eighty 
if %last7%==9 set spell7=Ninety 
if %last7%==0 set spell7=

:d6
set ls6=%dg:~-6%
set last6=%ls6:~0,1%
if %last6%==1 set spell6=One 
if %last6%==2 set spell6=Two 
if %last6%==3 set spell6=Three 
if %last6%==4 set spell6=Four 
if %last6%==5 set spell6=Five 
if %last6%==6 set spell6=Six 
if %last6%==7 set spell6=Seven 
if %last6%==8 set spell6=Eight 
if %last6%==9 set spell6=Nine 
if %last6%==0 set spell6=

if %len%==6 (set lac=Lac ) && GOTO d5
if %last7%==1 (if %last6%==0 set spell76=Ten )
if %last7%==1 (if %last6%==1 set spell76=Eleven )
if %last7%==1 (if %last6%==2 set spell76=Twelve )
if %last7%==1 (if %last6%==3 set spell76=Thirteen )
if %last7%==1 (if %last6%==4 set spell76=Fourteen )
if %last7%==1 (if %last6%==5 set spell76=Fifteen )
if %last7%==1 (if %last6%==6 set spell76=Sixteen )
if %last7%==1 (if %last6%==7 set spell76=Seventeen )
if %last7%==1 (if %last6%==8 set spell76=Eighteen )
if %last7%==1 (if %last6%==9 set spell76=Nineteen )
if %last6%==0 (if %last7%==0 (set lac=) ELSE (set lac=Lac )) ELSE (set lac=Lac )
if not %last7%==1 set spell76=%spell7%%spell6%

:d5
set ls5=%dg:~-5%
set last5=%ls5:~0,1%
if %last5%==2 set spell5=Twenty 
if %last5%==3 set spell5=Thirty 
if %last5%==4 set spell5=Forty 
if %last5%==5 set spell5=Fifty 
if %last5%==6 set spell5=Sixty 
if %last5%==7 set spell5=Seventy 
if %last5%==8 set spell5=Eighty 
if %last5%==9 set spell5=Ninety 
if %last5%==0 set spell5=

:d4
set ls4=%dg:~-4%
set last4=%ls4:~0,1%
if %last4%==1 set spell4=One 
if %last4%==2 set spell4=Two 
if %last4%==3 set spell4=Three 
if %last4%==4 set spell4=Four 
if %last4%==5 set spell4=Five 
if %last4%==6 set spell4=Six 
if %last4%==7 set spell4=Seven 
if %last4%==8 set spell4=Eight 
if %last4%==9 set spell4=Nine 
if %last4%==0 set spell4=

if %len%==4 (set thn=Thousand ) && GOTO d3

if %last5%==1 (if %last4%==0 set spell54=Ten )
if %last5%==1 (if %last4%==1 set spell54=Eleven )
if %last5%==1 (if %last4%==2 set spell54=Twelve )
if %last5%==1 (if %last4%==3 set spell54=Thirteen )
if %last5%==1 (if %last4%==4 set spell54=Fourteen )
if %last5%==1 (if %last4%==5 set spell54=Fifteen )
if %last5%==1 (if %last4%==6 set spell54=Sixteen )
if %last5%==1 (if %last4%==7 set spell54=Seventeen )
if %last5%==1 (if %last4%==8 set spell54=Eighteen )
if %last5%==1 (if %last4%==9 set spell54=Nineteen )
if %last4%==0 (if %last5%==0 (set thn=) ELSE (set thn=Thousand )) ELSE (set thn=Thousand )
if not %last5%==1 set spell54=%spell5%%spell4%

:d3
set ls3=%dg:~-3%
set last3=%ls3:~0,1%
if %last3%==1 set spell3=One 
if %last3%==2 set spell3=Two 
if %last3%==3 set spell3=Three 
if %last3%==4 set spell3=Four 
if %last3%==5 set spell3=Five 
if %last3%==6 set spell3=Six 
if %last3%==7 set spell3=Seven 
if %last3%==8 set spell3=Eight 
if %last3%==9 set spell3=Nine 
if %last3%==0 set spell3=
if %last3%==0 (set hnd=) ELSE (set hnd=Hundred )

:d2
set ls2=%dg:~-2%
set last2=%ls2:~0,1%
if %last2%==2 set spell2=Twenty 
if %last2%==3 set spell2=Thirty 
if %last2%==4 set spell2=Forty 
if %last2%==5 set spell2=Fifty 
if %last2%==6 set spell2=Sixty 
if %last2%==7 set spell2=Seventy 
if %last2%==8 set spell2=Eighty 
if %last2%==9 set spell2=Ninety 
if %last2%==0 set spell2=

:d1
set last1=%dg:~-1%
if %last1%==1 set spell1=One 
if %last1%==2 set spell1=Two 
if %last1%==3 set spell1=Three 
if %last1%==4 set spell1=Four 
if %last1%==5 set spell1=Five 
if %last1%==6 set spell1=Six 
if %last1%==7 set spell1=Seven 
if %last1%==8 set spell1=Eight 
if %last1%==9 set spell1=Nine 
if %last1%==0 set spell1=
if %len%==1 GOTO dn

if %last2%==1 (if %last1%==0 set spell21=Ten )
if %last2%==1 (if %last1%==1 set spell21=Eleven )
if %last2%==1 (if %last1%==2 set spell21=Twelve )
if %last2%==1 (if %last1%==3 set spell21=Thirteen )
if %last2%==1 (if %last1%==4 set spell21=Fourteen )
if %last2%==1 (if %last1%==5 set spell21=Fifteen )
if %last2%==1 (if %last1%==6 set spell21=Sixteen )
if %last2%==1 (if %last1%==7 set spell21=Seventeen )
if %last2%==1 (if %last1%==8 set spell21=Eighteen )
if %last2%==1 (if %last1%==9 set spell21=Nineteen )
if not %last2%==1 set spell21=%spell2%%spell1%

:dn

echo.
echo.

if %len%==10 echo %spell10%%bln%%spell98%%crr%%spell76%%lac%%spell54%%thn%%spell3%%hnd%%spell21%
if %len%==9 echo %spell98%%crr%%spell76%%lac%%spell54%%thn%%spell3%%hnd%%spell21%
if %len%==8 echo %spell8%%crr%%spell76%%lac%%spell54%%thn%%spell3%%hnd%%spell21%
if %len%==7 echo %spell76%%lac%%spell54%%thn%%spell3%%hnd%%spell21%
if %len%==6 echo %spell6%%lac%%spell54%%thn%%spell3%%hnd%%spell21%
if %len%==5 echo %spell54%%thn%%spell3%%hnd%%spell21%
if %len%==4 echo %spell4%%thn%%spell3%%hnd%%spell21%
if %len%==3 echo %spell3%%hnd%%spell21%
if %len%==2 echo %spell21%
if %len%==1 echo %spell1%

:end
pause


Report •

#6
April 12, 2009 at 21:33:04
yes, i couldn't hunt those ..
thanks a lot , now its working fine.
and yes please do suggest me optimisations
i am working on functions but havent succeded yet.

Report •


Ask Question