|
Post by get1960 on Jul 20, 2018 11:28:52 GMT -5
Hi. I know that this is probably a newbie question/situation. Why does this work for a string array?: E$="The quick brown fox jumps over the lazy dog"
But this does not work for a numeric array?: K=08091960
For the string array, I can access it and process the information. For the numeric array, I cannot do anything because nothing is loaded.
Why is that?
Thanks, George
|
|
|
Post by tenochtitlanuk on Jul 20, 2018 11:52:31 GMT -5
You need to check what is meant by an 'array'. NEITHER of your variables is an array!
If you want to access each object in the middle of a single string variable you use 'mid$('. This will work for a string containing ANY character whether an alphabet letter, symbol or representaion of a digit.
E$ ="The quick brown fox jumps over the lazy dog"
N$ ="08091960"
for i =1 to len( E$) print mid$( E$, i, 1); " - "; next i
print
for i =1 to len( N$) print mid$( N$, i, 1); " - "; next i
An array would be something like name$( 100) which could hold up to 100 people's names- or score( 100) which could hold their score in a programming test!
There's also a useful command 'word$(', which can say fetch in turn each word in your example sentence.
If you find it confusing after looking them up in the help files, get back here and tell us what you are trying to do. We sll found it confusing when we started coding!
|
|
|
Post by get1960 on Jul 20, 2018 17:29:11 GMT -5
Thanks for the response. As I said, the E$ one works. The N one does not. The E$ is alphanumeric. The N one is numeric only. N$ is defined as DIM N$(30). E is defined as DIM E(8). I did this and got it to work. E(1) = 0 E(2) = 1 E(3) = 2 E(4) = 3 E(5) = 4 E(6) = 5 E(7) = 6 E(8) = 7 You need to check what is meant by an 'array'. NEITHER of your variables is an array! If you want to access each object in the middle of a single string variable you use 'mid$('. This will work for a string containing ANY character whether an alphabet letter, symbol or representaion of a digit. E$ ="The quick brown fox jumps over the lazy dog"
N$ ="08091960"
for i =1 to len( E$) print mid$( E$, i, 1); " - "; next i
print
for i =1 to len( N$) print mid$( N$, i, 1); " - "; next i
An array would be something like name$( 100) which could hold up to 100 people's names- or score( 100) which could hold their score in a programming test! There's also a useful command 'word$(', which can say fetch in turn each word in your example sentence. If you find it confusing after looking them up in the help files, get back here and tell us what you are trying to do. We sll found it confusing when we started coding!
|
|
|
Post by tenochtitlanuk on Jul 21, 2018 2:26:00 GMT -5
Indeed= you now are using an array.
In these kind of cases you could still have used a single string and extracted the VALUES of each digit if you wanted them as numeric digits... that's why I asked what you were wanting to do. The important thing is to know that digits in a number are not the same as characters in a string.
N$ ="08091960"
for i =1 to len( N$) print val( mid$( N$, i, 1)); " - "; next i
|
|
|
Post by bluatigro on Jul 24, 2018 1:11:16 GMT -5
you can try this :
w$ = "the quick broun fox juped over the lazy dog" number$ = "1 10 100 4 5 6 7 8 9"
for i = 1 to 9 a$ = word$( w$ , i )
x = val( word$( number$ , i )
print x , a$
next i
in this way you can create a dinamic array whitch can used as a parameter for a function or a sub
|
|
|
Post by jkintn on Feb 7, 2019 16:05:52 GMT -5
Maybe you can take "K" and obtain the string representation (call that K$). Then work with K$ (as you do with E$ )- or - read components of K$, convert to numbers and fill array E() - assuming that is your goal. This probably does not help, but you original post is not clear to me. (It seems like a spreadsheet task???)
|
|