QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: krovit on February 04, 2020, 05:20:40 am

Title: DIM array
Post by: krovit on February 04, 2020, 05:20:40 am
Have patience, please...
I am seriously worried: could I have forgotten things I know I already know? Old age?

When sizing or resizing an array, you assign a space to the variables.
The space, at the beginning, is obviously empty (the variables are zeo or null).

Question: is there any way to know if any of the indexed variables has a value different from zeo or different from null?

Title: Re: DIM array
Post by: krovit on February 04, 2020, 07:39:19 am
Excuse me... of course my question refers to a possible alternative of a FOR-NEXT that scans the whole array
Title: Re: DIM array
Post by: SMcNeill on February 04, 2020, 07:48:34 am
Sorry.  I think a FOR.. NEXT loop would probably be your best way to check for the existence of non-zero values. 
Title: Re: DIM array
Post by: bplus on February 04, 2020, 11:51:45 am
Hi krovit,

Here is my test:
Code: QB64: [Select]
  1. REDIM arr$(1 TO 10)
  2. i = 1
  3. WHILE i <= 10
  4.     arr$(i) = CHR$(i + 32)
  5.     PRINT arr$(i); "  ";
  6.     i = i + 1
  7. REDIM _PRESERVE arr$(1 TO 20)
  8. i = 1
  9. WHILE i <= 20
  10.     PRINT arr$(i); "  ";
  11.     i = i + 1
  12. PRINT:: PRINT: PRINT "Now try Type:" 'sometimes Type makes up stuff
  13. TYPE xy
  14.     x AS STRING
  15.     y AS STRING
  16.  
  17. REDIM arr(1 TO 10) AS xy
  18. i = 1
  19. WHILE i <= 10
  20.     arr(i).x = CHR$(i + 32)
  21.     PRINT arr(i).x; ","; arr(i).y; "  ";
  22.     i = i + 1
  23. REDIM _PRESERVE arr(1 TO 20) AS xy
  24. i = 1
  25. WHILE i <= 20
  26.     PRINT arr(i).x; ","; arr(i).y; "  ";
  27.     i = i + 1
  28.  
  29.  

EDIT for strings, well today I couldn't get garbage in unassigned values, 0's or nothings here but as I recall this is not always the case.

Title: Re: DIM array
Post by: krovit on February 05, 2020, 04:47:11 am
Thank you bplus!