Page 1 of 1
Subs, functions, indexing arrays
Posted: Mon Oct 31, 2016 7:26 pm
by Tontoinjun
I have been trying to write a sub or function that will return the index number of a 1 dim array of strings when a string I is submitted and a match is found. The problem is submitting a string and returning an integer.
Input " name"; name
For I = 1 to 32
If name = namearray(I)
Then index = I
Next
How do you put in a sub or function?
Re: Subs, functions, indexing arrays
Posted: Sat Nov 05, 2016 9:16 am
by burger2227
Code: Select all
DIM SHARED namearray(1 TO 32) AS STRING 'shared array will need names put into it earlier with DATA or file input
Input " name"; name$
position% = index%(name$)
IF position% THEN PRINT name$; position%
FUNCTION index%(n$)
For I = 1 to 32
If n$ = namearray(I) Then index% = I : EXIT FUNCTION ' exits at first name match
Next ' exits with last name match position or 0
END FUNCTION
Re: Subs, functions, indexing arrays
Posted: Fri Nov 11, 2016 8:04 pm
by Tontoinjun
Thank you! That solved the problem that I have racked my brain over. What a relief. Thanks again.