Array issue - out of range

4 posts / 0 new
Last post
borderraux
Offline
Joined: 10/22/2018 - 08:39
Array issue - out of range

Hi 
I am having some issues with array declaration - the values for 4 elements of my array come from droplistbox in a dialog box however the code stops at first line of my array declaration:
 
UserSelection(1) = DateFieldArray(UserBox.DropListBox1))  and generates the error: "subscript aout of range.
 I cannot figure out the issue since i declared my UserSelection array as 4 elements array.
Code attached
 

Brian Element's picture
Brian Element
Online
Joined: 07/11/2012 - 19:57

It is because you have use the Option Base 1 for your arrays, so that means your array cannot contain a 0.  For each of your UserBox.DropListBox1 if you select the first item on the list that item will return 0, it is just the way the DropListBox is built.  So you have to make sure that since your arrays all start at 1 that you always add 1 for each UserBox.DropListBox that you access.  So all your arrays need to have the one added to it such as:

UserSelection(1) = DateFieldArray(UserBox.DropListBox1+1)

Your errors where for the selections where you weren't add 1 to the UserBox.DropListBox1.

Hope that helps out and welcome to the site.

Brian

borderraux
Offline
Joined: 10/22/2018 - 08:39

Thank you Brian.
It is puzzling me because i thought that could be an issue since i started declaring my array from 1 rather than 0 however i did run it with +1 option after DropListbox(number) and it didnt work however i think I also might have each Redim Preserve line for each DropListbox set with (j-1) i.e: ReDim Preserve SecDBDateFieldArray(j-1)  and that might have casued some issue too.
It works now so many thanks and thank you for having me on your forum.

Brian Element's picture
Brian Element
Online
Joined: 07/11/2012 - 19:57

The thing is you would only get the error if you selected the first item in the drop-down.  If you selected any others there would be no error but you would not have got the field you expected, you would have had the next one down.