## Problem with "asc(\$)"...

Expand Messages
• Hi friends, Could somebody tell me why the followinf littel est does nt work and stop at the line
Message 1 of 2 , Jul 7, 2009
• 0 Attachment
Hi friends,

Could somebody tell me why the followinf littel est does'nt work and stop at the line <========== ?

Thousand thanks in anticipation,
Marc from France.

=====================================================================
'TEST DE TRI ALPHABETIQUE

'What is the problem on line <============ ?

N\$(1)="ALGLAVE"
N\$(2)="DURIEUX"
N\$(3)="ANDRIEUX"

for I=1 to 3
print N\$(I)
LN=len(N\$(I))
for J=1 to LN
L\$=MID\$(N\$(I), j, 1)
AS=asc(L\$)' <============
N(I)=N(I)+AS
next J
next I

for I=1 to 3
PRINT N\$(I);" ";N(I)
next I

'then it will be easiest for me to use the SORT code of LB with numerical array\$()
=====================================================================
• ... You are using a capital J for the loop index, but you are using a non-capital j for the positional index in the MID\$() function. AS is a reserved word, see
Message 2 of 2 , Jul 7, 2009
• 0 Attachment
>
> Could somebody tell me why the followinf littel est does'nt
> work and stop at the line <========== ?
>
---snip
> for J=1 to LN
> L\$=MID\$(N\$(I), j, 1)
> AS=asc(L\$)' <============
---snip
>
> 'then it will be easiest for me to use the SORT code of LB
> with numerical array\$()
> =====================================================================
>

You are using a capital J for the loop index, but you are using a non-capital j for the positional index in the MID\$() function.
AS is a reserved word, see NAME..AS, OPEN..AS and CALLDLL ({variable} AS {type}).

To correct this use a capital J for MID\$() too.

BTW, anagrams will result in the same numerical value OTTO = TOOT, if you only use the ASCII value of the characters.
You should base the value on the position too.

'---code start (watch for line wraps)
DIM N\$(5), N(5)

N\$(1)="ALGLAVE"
N\$(2)="DURIEUX"
N\$(3)="ANDRIEUX"
N\$(4)="OTTO"
N\$(5)="TOOT"

for I=1 to 5
LN=len(N\$(I))
for J=1 to LN
L\$=MID\$(N\$(I), J, 1)
ASI=asc(L\$)
N(I)=N(I)+ASI
next J
next I

for I=1 to 5
PRINT N\$(I);" ";N(I)
next I

REDIM N(5)
PRINT

for I=1 to 5
LN=len(N\$(I))
for J=1 to LN
L\$=MID\$(N\$(I), J, 1)
ASI=asc(L\$)
N(I)=N(I)+ASI*256^(J-1)
next J
next I

for I=1 to 5
PRINT N\$(I);" ";N(I)
next I
'---code end

---
Stefan Pendl

Liberty BASIC Assist 4.03 ........ http://www.libertybasic.com/assist.html
Liberty BASIC 4.04 public beta ... http://www.libertybasic.com/lb404b3setup.exe

Windows Vista Home Premium 32-bit SP2
AMD Turion X2 RM-70 2GHz
4GB RAM
Your message has been successfully submitted and would be delivered to recipients shortly.