Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UBOUND
#1
As you can see, I'm in the mood for questions.

Look at this:
Code: (Select All)

OPTION _EXPLICIT
DIM myArray%(5)
PRINT UBOUND(myArray%)

the result is "5".

Fine.

Look at this:
Code: (Select All)

OPTION _EXPLICIT
DIM myArray%
PRINT UBOUND(myArray%)

This is less "fine".
1. If OPTION_EXPLICIT is activeted, it says "myArray" is not defined.... why?
2. If OPTION_EXPLICIT is deactiveted, the result is "10"... why?
Reply
#2
(02-03-2024, 08:54 PM)bartok Wrote: As you can see, I'm in the mood for questions.

Look at this:
Code: (Select All)

OPTION _EXPLICIT
DIM myArray%(5)
PRINT UBOUND(myArray%)

the result is "5".

Fine.

Look at this:
Code: (Select All)

OPTION _EXPLICIT
DIM myArray%
PRINT UBOUND(myArray%)

This is less "fine".
1. If OPTION_EXPLICIT is activeted, it says "myArray" is not defined.... why?
2. If OPTION_EXPLICIT is deactiveted, the result is "10"... why?

DIM myArray% is only a varaible NOT an array it needs the () for an array Ubound can make sense of.
b = b + ...
Reply
#3
To highlight what bplus is saying:

DIM x
DIM x(5)

Of the above, which is a variable and which is an array?

That's basically what you've did in your code.
Reply
#4
(02-03-2024, 10:28 PM)SMcNeill Wrote: To highlight what bplus is saying:

DIM x
DIM x(5)

Of the above, which is a variable and which is an array?

That's basically what you've did in your code.
I thought that "x" was an array 1 x 1, as to say made by 1 variable and I thought that x(5) was an array 6 x 1, made by 6 varibles... so to:

Code: (Select All)

OPTION _EXPLICIT
OPTION BASE 1
DIM myArray%
PRINT UBOUND(myArray%)

I expected the answer "1".

So, what is the difference beetween:

DIM x%(1) and DIM x%?

(I generally use OPTION BASE 1. Without it I would expected "0" and DIM x%(1) would be DIM x%(0))
Reply
#5
DIM X(1) is an array with one element.
DIM X is a variable.

SUB foo(x, y() )

Now, in that SUB, what values can you pass to those parameters?
For x, you pass a single value, or a variable.
Your y(), you pass a whole array.

A variable is NOT the same as a single element array.

Variables can never be REDIMed to hold more elements.  They have no indexes.  The contain just a single value.  

Even a single-element array has an index.  X(0).  This index tells you, "THIS IS NOT A VARIABLE."  Don't fool yourself into thinking it is.
Reply
#6
(02-04-2024, 12:28 PM)SMcNeill Wrote: DIM X(1) is an array with one element.
DIM X is a variable.

SUB foo(x, y() )

Now, in that SUB, what values can you pass to those parameters?
For x, you pass a single value, or a variable.
Your y(), you pass a whole array.

A variable is NOT the same as a single element array.

Variables can never be REDIMed to hold more elements.  They have no indexes.  The contain just a single value.  

Even a single-element array has an index.  X(0).  This index tells you, "THIS IS NOT A VARIABLE."  Don't fool yourself into thinking it is.
Ok, It's clear. Thank's!
Reply




Users browsing this thread: 1 Guest(s)