Author Topic: DIM array  (Read 2844 times)

0 Members and 1 Guest are viewing this topic.

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
DIM array
« 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?

Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: DIM array
« Reply #1 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
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: DIM array
« Reply #2 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. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: DIM array
« Reply #3 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.

« Last Edit: February 04, 2020, 12:06:05 pm by bplus »

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: DIM array
« Reply #4 on: February 05, 2020, 04:47:11 am »
Thank you bplus!
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)