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?
Subs, functions, indexing arrays
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Re: Subs, functions, indexing arrays
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
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
-
- Newbie
- Posts: 2
- Joined: Mon Oct 31, 2016 6:33 pm
Re: Subs, functions, indexing arrays
Thank you! That solved the problem that I have racked my brain over. What a relief. Thanks again.