Jump to content

Recommended Posts

Posted (edited)

#include <File.au3>
#include <Array.au3>

Local $EC
_FileReadToArray(@ScriptDir & "\Data.txt", $EC)

Local $EL[$EC[0]]

For $i = 1 To $EC[0]
    $EL[$i - 1] = StringTrimLeft($EC[$i], "2")

Next


Local $string = "a"
Local $codedstring

$string = StringSplit($string, ""); splits string into array



For $letter In $string
    Select
        Case $letter = "a"
            $codedstring = $codedstring & $EL[1]
        Case $letter = "b"
            $codedstring = $codedstring & $EL[2]
        Case $letter = "c"
            $codedstring = $codedstring & $EL[3]
        Case $letter = "d"
            $codedstring = $codedstring & $EL[4]
        Case $letter = "e"
            $codedstring = $codedstring & $EL[5]
        Case $letter = "f"
            $codedstring = $codedstring & $EL[6]
        Case $letter = "g"
            $codedstring = $codedstring & $EL[7]
        Case $letter = "h"
            $codedstring = $codedstring & $EL[8]
        Case $letter = "i"
            $codedstring = $codedstring & $EL[9]
        Case $letter = "j"
            $codedstring = $codedstring & $EL[10]
        Case $letter = "k"
            $codedstring = $codedstring & $EL[11]
        Case $letter = "l"
            $codedstring = $codedstring & $EL[12]
        Case $letter = "m"
            $codedstring = $codedstring & $EL[13]
        Case $letter = "n"
            $codedstring = $codedstring & $EL[14]
        Case $letter = "o"
            $codedstring = $codedstring & $EL[15]
        Case $letter = "p"
            $codedstring = $codedstring & $EL[16]
        Case $letter = "q"
            $codedstring = $codedstring & $EL[17]
        Case $letter = "r"
            $codedstring = $codedstring & $EL[18]
        Case $letter = "s"
            $codedstring = $codedstring & $EL[19]
        Case $letter = "t"
            $codedstring = $codedstring & $EL[20]
        Case $letter = "u"
            $codedstring = $codedstring & $EL[21]
        Case $letter = "v"
            $codedstring = $codedstring & $EL[22]
        Case $letter = "w"
            $codedstring = $codedstring & $EL[23]
        Case $letter = "x"
            $codedstring = $codedstring & $EL[24]
        Case $letter = "y"
            $codedstring = $codedstring & $EL[25]
        Case $letter = "z"
            $codedstring = $codedstring & $EL[26]
        Case $letter = "0"
            $codedstring = $codedstring & $EL[27]
        Case $letter = "1"
            $codedstring = $codedstring & $EL[28]
        Case $letter = "2"
            $codedstring = $codedstring & $EL[29]
        Case $letter = "3"
            $codedstring = $codedstring & $EL[30]
        Case $letter = "4"
            $codedstring = $codedstring & $EL[31]
        Case $letter = "5"
            $codedstring = $codedstring & $EL[32]
        Case $letter = "6"
            $codedstring = $codedstring & $EL[33]
        Case $letter = "7"
            $codedstring = $codedstring & $EL[34]
        Case $letter = "8"
            $codedstring = $codedstring & $EL[35]
        Case $letter = "9"
            $codedstring = $codedstring & $EL[36]
        Case $letter = " "
            $codedstring = $codedstring & $EL[37]
    EndSelect

Next

MsgBox(0, "", $codedstring)

a=5027
b=0675
c=1635
d=9564
e=5628
f=7143
g=2047
h=3454
i=1867
j=8896
k=6761
l=6456
m=3425
n=7561
o=4752
p=9471
q=1534
r=7616
s=2561
t=0610
u=0518
v=8645
w=2387
x=5432
y=5413
z=1556
0=6654
1=6467
2=6554
3=7635
4=2556
5=1324
6=3242
7=3453
8=8382
9=1343
 =2186

When I run the script it gives me "65540675" when it should be "5027", I've probably overlooked the obvious problem, anyway thanks.

Edited by FinalVersion
Posted

When I run the script it gives me "65540675" when it should be "5027", I've probably overlooked the obvious problem, anyway thanks.

Have you looked at the content of the $string array? It looks like this:

[0] 1

[1] a

When you use the For...In... loop it looks at every element in your array, starting at [0]. So your code string will be twice as long as expected. Find a way to ignore the [0] array element

Secondly, have a look at your $EL array, I think you're expecting $EL[1] to be 5027, when in fact $EL[0] is 5027.

It's entirely up to you how you work with arrays, but I always find that avoiding use of the zeroeth array index for data storage makes things easier to understand.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Posted (edited)

I justed set

StringSplit($string, "")
to
StringSplit($string, "", 2)
; adding the flag "2" stops the first element of the array being the total of elements in the array.

Then i've changed each $EL[] in the select statement to reflect my -1 amendment to the array.... the array now starts @ 0 and not 1

Hope it helps.

#include <File.au3>
#include <Array.au3>

Local $EC
_FileReadToArray(@ScriptDir & "\Data.txt", $EC)

Local $EL[$EC[0]]

For $i = 1 To $EC[0]
    $EL[$i - 1] = StringTrimLeft($EC[$i], "2")

Next


Local $string = "a"
Local $codedstring

$string = StringSplit($string, "", 2); splits string into array



For $letter In $string
    Select
        Case $letter = "a"
            $codedstring = $codedstring & $EL[0]
        Case $letter = "b"
            $codedstring = $codedstring & $EL[1]
        Case $letter = "c"
            $codedstring = $codedstring & $EL[2]
        Case $letter = "d"
            $codedstring = $codedstring & $EL[3]
        Case $letter = "e"
            $codedstring = $codedstring & $EL[4]
        Case $letter = "f"
            $codedstring = $codedstring & $EL[5]
        Case $letter = "g"
            $codedstring = $codedstring & $EL[6]
        Case $letter = "h"
            $codedstring = $codedstring & $EL[7]
        Case $letter = "i"
            $codedstring = $codedstring & $EL[8]
        Case $letter = "j"
            $codedstring = $codedstring & $EL[9]
        Case $letter = "k"
            $codedstring = $codedstring & $EL[10]
        Case $letter = "l"
            $codedstring = $codedstring & $EL[11]
        Case $letter = "m"
            $codedstring = $codedstring & $EL[12]
        Case $letter = "n"
            $codedstring = $codedstring & $EL[13]
        Case $letter = "o"
            $codedstring = $codedstring & $EL[14
        Case $letter = "p"
            $codedstring = $codedstring & $EL[15]
        Case $letter = "q"
            $codedstring = $codedstring & $EL[16]
        Case $letter = "r"
            $codedstring = $codedstring & $EL[17]
        Case $letter = "s"
            $codedstring = $codedstring & $EL[18]
        Case $letter = "t"
            $codedstring = $codedstring & $EL[19]
        Case $letter = "u"
            $codedstring = $codedstring & $EL[20]
        Case $letter = "v"
            $codedstring = $codedstring & $EL[21]
        Case $letter = "w"
            $codedstring = $codedstring & $EL[22]
        Case $letter = "x"
            $codedstring = $codedstring & $EL[23]
        Case $letter = "y"
            $codedstring = $codedstring & $EL[24]
        Case $letter = "z"
            $codedstring = $codedstring & $EL[25]
        Case $letter = "0"
            $codedstring = $codedstring & $EL[26]
        Case $letter = "1"
            $codedstring = $codedstring & $EL[27]
        Case $letter = "2"
            $codedstring = $codedstring & $EL[28]
        Case $letter = "3"
            $codedstring = $codedstring & $EL[29]
        Case $letter = "4"
            $codedstring = $codedstring & $EL[30]
        Case $letter = "5"
            $codedstring = $codedstring & $EL[31]
        Case $letter = "6"
            $codedstring = $codedstring & $EL[32]
        Case $letter = "7"
            $codedstring = $codedstring & $EL[33]
        Case $letter = "8"
            $codedstring = $codedstring & $EL[34]
        Case $letter = "9"
            $codedstring = $codedstring & $EL[35]
        Case $letter = " "
            $codedstring = $codedstring & $EL[36]
    EndSelect

Next

MsgBox(0, "", $codedstring)
Edited by Steveiwonder

They call me MrRegExpMan

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...