Uninitilaized variable Error Message on VARDIM1 and VARDIM2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2011-01-12 06:09 AM
‎2011-01-12
06:09 AM
! Example from GDL Reference Guide Page 237
DIM f1 [5]
FOR i = 1 TO VARDIM1(f1) ! Uninitialized variable Error Message here
f1
NEXT i
But if I do this, the Error Message will not come up:
DIM f1 [5]
f1[1] = 0
f1[2] = 0
f1[3] = 0
f1[4] = 0
f1[5] = 0
FOR i = 1 TO VARDIM1(f1)
f1
NEXT i
Is there any way to overcome this problem ?
Regards,
Hoa
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2011-01-12 06:26 AM
‎2011-01-12
06:26 AM
"From the GDL manual wrote:
VARDIM1(expr)
VARDIM1(expr)
VARDIM2(expr)
VARDIM2(expr)
These functions return as integers the actual dimension values for the (array) expression specified as a parameter. They must be used if you want
to handle correctly all actual elements of a dynamic array or an array parameter. If no element of a dynamic array was previously set, the return
value is 0. For one-dimensional arrays VARDIM2 returns 0.
So you are saying to go FOR i = 1 to 0
But in you second part of the example you have given values to tha array so it now works.
Why don't you just say ...
FOR i = 1 TO 5
f1
NEXT i
Barry.
One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11