Searching for empty arrays

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

kinosh
Newbie
Posts: 1
Joined: Mon Jan 23, 2017 7:49 pm

Searching for empty arrays

Postby kinosh » Mon Jan 23, 2017 7:53 pm

I have an array, some contain strings and some are empty (no integers). Is there a way to find the empty arrays?

User avatar
burger2227
Veteran
Posts: 2144
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: Searching for empty arrays

Postby burger2227 » Wed Jan 25, 2017 8:49 pm

LEN can tell you how long a string is in each part of the array. 0 is an empty index.

Code: Select all

DIM array$(100)

FOR i = 0 TO 99  'set indices
    array$(i) = "AA"
NEXT

PRINT array$(50)  'read an index
PRINT LEN(array$(50)) 'display length of string

PRINT LEN(array$)

You will have to read each index using a FOR loop.
LEN can NOT be used on numerical arrays as it will only show the number's
byte size which never changes even for 0.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : http://www.QB64.NET
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0


Return to “QBASIC and QB64 Questions & Answers”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 9 guests