' This program does not work for a reason that escapes me.
' all variable assignations have been simplified from my
' original version to aid reading/debugging. Reading
' back of the array just doesn't seem to work and with
' illogical patterns. The IOS device used is for programming
' is an iPad Pro with 128gb (top model).
' Use of OPTION BASE(x) does not seem to help.
' Note: in references to 'x,x' in notes 'x' is not a variable!
' Any feedback from the forum would be appreciated.
DIM A$(63,4) ' main DATA reference array
arraychar=62 ' primary characters
optchar=3 ' sub characters
counter=0
' **** Read data ****
FOR loop1=0 TO arraychar
FOR loop2=0 TO optchar
READ A$(loop1,loop2)
NEXT loop2
NEXT loop1
' ****
' Print out all the READ data.
TEXT CLEAR
FOR loop3=0 TO arraychar
PRINT A$(loop3,0);" ";A$(loop3,1);" ";A$(loop3,2);" ";A$(loop3,3)
NEXT loop3
' **** Input character string to array ****
INPUT "Enter a word? (up to 12 characters for testing)":userword$
capword$=CAPSTR$(userword$) ' capitalise input string
wordlength=(LEN(userword$))
DIM wordarray$(wordlength+1)
' ****
FOR loop4=0 TO wordlength-1
wordletter$=SUBSTR$(userword$,loop4,loop4)
wordarray$(loop4)=wordletter$
NEXT loop4
' ****
PRINT ! PRINT
PRINT userword$ ' input string
PRINT capword$ ' capitalised input string
PRINT
PRINT wordlength; "characters" ' length of input string
PRINT
' ****
FOR loop5=0 TO wordlength-1
PRINT wordarray$(loop5);
NEXT loop5
PRINT ! PRINT
' **** Create 2nd array based on input string ****
DIM varified$(wordlength+1,4)
FOR loop5=0 TO wordlength ' loop once for each character of input string
FOR loop6=0 TO arraychar ' loop x number of data arrays
IF wordarray$(counter)=A$(loop6,0) THEN ' test input character against first of each data array
varified$(loop5,0)=A$(loop6,0) ' if character matches DATA (A$(x,0)) then
varified$(loop5,1)=A$(loop6,1) ' assign A$(x,0),(x,1),(x,2),(x,3) to varified$(x,x)
varified$(loop5,2)=A$(loop6,2)
varified$(loop5,3)=A$(loop6,3)
PRINT varified$(loop5,0); ' print to confirm conversion/data read
PRINT varified$(loop5,1);
PRINT varified$(loop5,2);
PRINT varified$(loop5,3)
counter +=1
ENDIF
NEXT loop6
NEXT loop5
' ****
' Read back data from varified(x,x). Notice characters
' that are missing. If you input a different string
' the letters that are missing could be
' ones that previously printed and vice versa. There
' appears to be no consistent pattern as to which are
' printed and which aren't. The only consistency is
' that a given input will always produce the same
' output pattern. I have removed lines that individally
' did the same as loop 7, the result was always idendtical
' so the loop is okay.
PRINT ! PRINT
FOR loop7=0 TO wordlength
PRINT varified$(loop7,0);
PRINT varified$(loop7,1);
PRINT varified$(loop7,2);
PRINT varified$(loop7,3)
NEXT loop7
END
DATA "~","1","2","3"
DATA "A","1","2","3"
DATA "B","1","2","3"
DATA "C","1","2","3"
DATA "D","1","2","3"
DATA "E","1","2","3"
DATA "F","1","2","3"
DATA "G","1","2","3"
DATA "H","1","2","3"
DATA "I","1","2","3"
DATA "J","1","2","3"
DATA "K","1","2","3"
DATA "L","1","2","3"
DATA "M","1","2","3"
DATA "N","1","2","3"
DATA "O","1","2","3"
DATA "P","1","2","3"
DATA "Q","1","2","3"
DATA "R","1","2","3"
DATA "S","1","2","3"
DATA "T","1","2","3"
DATA "U","1","2","3"
DATA "V","1","2","3"
DATA "W","1","2","3"
DATA "X","1","2","3"
DATA "Y","1","2","3"
DATA "Z","1","2","3"
DATA "a","1","2","3"
DATA "b","1","2","3"
DATA "c","1","2","3"
DATA "d","1","2","3"
DATA "e","1","2","3"
DATA "f","1","2","3"
DATA "g","1","2","3"
DATA "h","1","2","3"
DATA "i","1","2","3"
DATA "j","1","2","3"
DATA "k","1","2","3"
DATA "l","1","2","3"
DATA "m","1","2","3"
DATA "n","1","2","3"
DATA "o","1","2","3"
DATA "p","1","2","3"
DATA "q","1","2","3"
DATA "r","1","2","3"
DATA "s","1","2","3"
DATA "t","1","2","3"
DATA "u","1","2","3"
DATA "v","1","2","3"
DATA "w","1","2","3"
DATA "x","1","2","3"
DATA "y","1","2","3"
DATA "z","1","2","3"
DATA "1","1","2","3"
DATA "2","1","2","3"
DATA "3","1","2","3"
DATA "4","1","2","3"
DATA "5","1","2","3"
DATA "6","1","2","3"
DATA "7","1","2","3"
DATA "8","1","2","3"
DATA "9","1","2","3"
DATA "0","1","2","3"
Array problems - help needed.
Re: Array problems - help needed.
If the expected result is like the attached
screenshot, then just replace your counter
variable with loop5 variable...
(Upps Debug Pause now removed)
screenshot, then just replace your counter
variable with loop5 variable...
(Upps Debug Pause now removed)
Code: Select all
' This program does not work for a reason that escapes me.
' all variable assignations have been simplified from my
' original version to aid reading/debugging. Reading
' back of the array just doesn't seem to work and with
' illogical patterns. The IOS device used is for programming
' is an iPad Pro with 128gb (top model).
' Use of OPTION BASE(x) does not seem to help.
' Note: in references to 'x,x' in notes 'x' is not a variable!
' Any feedback from the forum would be appreciated.
DIM A$(63,4) ' main DATA reference array
arraychar=62 ' primary characters
optchar=3 ' sub characters
counter=0
' **** Read data ****
FOR loop1=0 TO arraychar
FOR loop2=0 TO optchar
READ A$(loop1,loop2)
NEXT loop2
NEXT loop1
' ****
' Print out all the READ data.
TEXT CLEAR
FOR loop3=0 TO arraychar
PRINT A$(loop3,0);" ";A$(loop3,1);" ";A$(loop3,2);" ";A$(loop3,3)
NEXT loop3
' **** Input character string to array ****
INPUT "Enter a word? (up to 12 characters for testing)":userword$
capword$=CAPSTR$(userword$) ' capitalise input string
wordlength=(LEN(userword$))
DIM wordarray$(wordlength+1)
' ****
FOR loop4=0 TO wordlength-1
wordletter$=SUBSTR$(userword$,loop4,loop4)
wordarray$(loop4)=wordletter$
NEXT loop4
' ****
PRINT ! PRINT
PRINT userword$ ' input string
PRINT capword$ ' capitalised input string
PRINT
PRINT wordlength; "characters" ' length of input string
PRINT
' ****
FOR loop5=0 TO wordlength-1
PRINT wordarray$(loop5);
NEXT loop5
PRINT ! PRINT
' **** Create 2nd array based on input string ****
DIM varified$(wordlength+1,4)
FOR loop5=0 TO wordlength
' loop once for each character of input string
FOR loop6=0 TO arraychar
' loop x number of data arrays
IF wordarray$(loop5)=A$(loop6,0) THEN
' test input character against first of each data array
varified$(loop5,0) = A$(loop6,0)
' if character matches DATA (A$(x,0)) then
varified$(loop5,1)=A$(loop6,1) ' assign A$(x,0),(x,1),(x,2),(x,3) to varified$(x,x)
varified$(loop5,2)=A$(loop6,2)
varified$(loop5,3)=A$(loop6,3)
PRINT varified$(loop5,0); ' print to confirm conversion/data read
PRINT varified$(loop5,1);
PRINT varified$(loop5,2);
PRINT varified$(loop5,3)
'DEBUG PAUSE
'counter +=1
ENDIF
NEXT loop6
NEXT loop5
'DEBUG PAUSE
' ****
' Read back data from varified(x,x). Notice characters
' that are missing. If you input a different string
' the letters that are missing could be
' ones that previously printed and vice versa. There
' appears to be no consistent pattern as to which are
' printed and which aren't. The only consistency is
' that a given input will always produce the same
' output pattern. I have removed lines that individally
' did the same as loop 7, the result was always idendtical
' so the loop is okay.
PRINT ! PRINT
FOR loop7=0 TO wordlength
PRINT varified$(loop7,0);
PRINT varified$(loop7,1);
PRINT varified$(loop7,2);
PRINT varified$(loop7,3)
NEXT loop7
END
DATA "~","1","2","3"
DATA "A","1","2","3"
DATA "B","1","2","3"
DATA "C","1","2","3"
DATA "D","1","2","3"
DATA "E","1","2","3"
DATA "F","1","2","3"
DATA "G","1","2","3"
DATA "H","1","2","3"
DATA "I","1","2","3"
DATA "J","1","2","3"
DATA "K","1","2","3"
DATA "L","1","2","3"
DATA "M","1","2","3"
DATA "N","1","2","3"
DATA "O","1","2","3"
DATA "P","1","2","3"
DATA "Q","1","2","3"
DATA "R","1","2","3"
DATA "S","1","2","3"
DATA "T","1","2","3"
DATA "U","1","2","3"
DATA "V","1","2","3"
DATA "W","1","2","3"
DATA "X","1","2","3"
DATA "Y","1","2","3"
DATA "Z","1","2","3"
DATA "a","1","2","3"
DATA "b","1","2","3"
DATA "c","1","2","3"
DATA "d","1","2","3"
DATA "e","1","2","3"
DATA "f","1","2","3"
DATA "g","1","2","3"
DATA "h","1","2","3"
DATA "i","1","2","3"
DATA "j","1","2","3"
DATA "k","1","2","3"
DATA "l","1","2","3"
DATA "m","1","2","3"
DATA "n","1","2","3"
DATA "o","1","2","3"
DATA "p","1","2","3"
DATA "q","1","2","3"
DATA "r","1","2","3"
DATA "s","1","2","3"
DATA "t","1","2","3"
DATA "u","1","2","3"
DATA "v","1","2","3"
DATA "w","1","2","3"
DATA "x","1","2","3"
DATA "y","1","2","3"
DATA "z","1","2","3"
DATA "1","1","2","3"
DATA "2","1","2","3"
DATA "3","1","2","3"
DATA "4","1","2","3"
DATA "5","1","2","3"
DATA "6","1","2","3"
DATA "7","1","2","3"
DATA "8","1","2","3"
DATA "9","1","2","3"
DATA "0","1","2","3"
- Attachments
-
- image.jpg (54.35 KiB) Viewed 2125 times
- mmtuk
- Posts: 16
- Joined: Sun Jan 25, 2015 8:36 pm
- My devices: iPad Pro’, various PC's, loads of old MacBooks, even more old MIDI synths, interfaces, wind synths, FX units, mixers - in fact, an Aladdin’s cave of big boys toys! (and a wife to hide it all from)
Re: Array problems - help needed.
Thanks Operator, That works though I don't understand why the counter variable doesn't or why it causes such erratic output. It's obviously not needed so I can now proceed. a big, big, THANK YOU!
Re: Array problems - help needed.
welcome
You may leave the counter variable, but
then you will need to add: break loop6
just after: counter += 1
Your counter will/may count more then
once in one cpl. loop6 iteration. For
example if the input was: "Testing"
loop5 = 0, counter = 0
when T is found
loop5 = 0, counter = 1
now that counter is 1 the next char is e
and it will be found in the same iteration
of the inner loop (loop6)
when e is found
loop5 = 0, counter = 2
so now the first element of the varified$
array (T) is overwritten with (e)
....
loop5 <> counter
Use cmd.: debug pause just after counter += 1
to see...
You may leave the counter variable, but
then you will need to add: break loop6
just after: counter += 1
Your counter will/may count more then
once in one cpl. loop6 iteration. For
example if the input was: "Testing"
loop5 = 0, counter = 0
when T is found
loop5 = 0, counter = 1
now that counter is 1 the next char is e
and it will be found in the same iteration
of the inner loop (loop6)
when e is found
loop5 = 0, counter = 2
so now the first element of the varified$
array (T) is overwritten with (e)
....
loop5 <> counter
Use cmd.: debug pause just after counter += 1
to see...