-
Jun 5th, 2025, 03:13 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [Index was outside the bounds of the array.] But it's not
I keep getting a [Index was outside the bounds of the array.] for a Text Bool to CBool conversion. I have a 2D array, 27 Row, 3 Col. The call is to the row of 2 and the column of 2. See below. Yet the program keeps jumping to the catch, and I have a boolean variable that is used just before the first catch error and the result = the spreadsheet setting. Yet...... It errors. This just started and it was working fine with taking the Bool from the spreadsheet and place it in the checkbox selection. See below.
Not sure what could be happening, as this is strange. Below are all of the code I believe is needed for demonstration of the issue. Please what could be causing this unnormal event?
Loading the checkboxes options default settings, where the error occurs.
Code:
Dim x As Boolean = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_MAIN_AUTO_CLOSE, cCOL_START))
CK_AUTO_CLOSE_MAIN.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_MAIN_AUTO_CLOSE, cCOL_START))
CK_AUTO_ASSIGN_MAIN.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_MAIN_AUTO_ASSIGN, cCOL_START))
CK_AUTO_RELAUNCH_MAIN.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_MAIN_AUTO_RELAUNCH, cCOL_START))
CK_USE_CHECKLIST.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_GENERAL_USE_CHECKLIST, cCOL_START))
CK_AUTO_GEN_CHECKLIST.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_TASK_AUTO_CREATE_CHECKLIST, cCOL_START))
CK_AUTO_CREATE_PER_FOLDER.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_TASK_AUTO_CREATE_PER_FOLDER, cCOL_START))
CK_AUTO_LAUNCH_PI.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_GENERAL_AUTO_LAUNCH_PXX, cCOL_START))
CK_AUTO_LOAD_PI_LIST.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_GENERAL_AUTO_LOAD_PI_LIST, cCOL_START))
CK_AUTO_LAUNCH_RISK.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_GENERAL_AUTO_LAUNCH_RISK, cCOL_START))
CK_AUTO_OPEN_ATTACHMENTS.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_REVIEW_AUTO_OPEN_ATTACHMENTS, cCOL_START))
CK_AUTO_COMPARE_CHECKLIST.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_REVIEW_AUTO_COMPARE_CHECKLIST, cCOL_START))
CK_AUTO_RUN.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_GENERAL_AUTO_RUN, cCOL_START))
Spreadsheet data
Code:
Default Option DO Setting Comment
Main Auto Close TRUE Closed the Tab if it has a "Close" button (After Updates)
Main Auto Assign TRUE Re-assigns the Main to the user
Main Spare 1 FALSE Spare bit
Main Auto Relaunch TRUE Reopens the Main when the Main is Closed automatically
Assign Spare 1 FALSE
Task Auto Create Checklist FALSE Are we going to use a checklist in this TASK
Task Create PER Folder TRUE Creates the PER folder if needed
General Auto Run FALSE Let the program run indefinatly by it's self
General Auto Load PI List TRUE Automatically load the users PI list
General Auto Launch PI FALSE Automatically launch the next selected PI
General Auto Launch Risk Analysis FALSE Will automatically launch the risk check when the main is loaded
General Spare 2 FALSE
General Spare 3 FALSE
General Spare 4 FALSE
General Generate Checklist FALSE User is using a checklist
General Auto Open Attachments TRUE Automatically open any attachments that the PIT may have
Review Auto Compare Checklist TRUE Compare the checklist with the PER information
Application Running 0 1 = Running; This is set to 1 at start. Prevent restart since it will be 1 on the next false start (DOES NOT WORK)
Country United States TRUE United States
Country China TRUE China
Country Austrailia TRUE Austrailia
Country Germany FALSE Germany
Country Japan TRUE Japan
Country United Kindom TRUE United Kindom
Country Brazil FALSE Brazil
Country Sweden TRUE Sweden
Values in some of the array.
Code:
(1, 1) "Default Option" Object {String}
(1, 2) "DO Setting" Object {String}
(1, 3) "Comment" Object {String}
(2, 1) "Main Auto Close" Object {String}
(2, 2) "True" Object {String}
(2, 3) "Closed the Tab if it has a ""Close"" button (After Updates)" Object {String}
(3, 1) "Main Auto Assign" Object {String}
(3, 2) "True" Object {String}
(3, 3) "Re-assigns the Main to the user" Object {String}
(4, 1) "Main Spare 1" Object {String}
(4, 2) False Object {Boolean}
(4, 3) "Spare bit" Object {String}
This is in the Load section of the main Form, and is before the GUI is displayed.
I can let it "Error" and then reset the run location back to the error location, and It will run that again without fail. However, the next item to be called fails, and so on wash, rinse, repeat.
EDIT: Thought someone might ask for the ENUM section. See below.
Code:
'--------------------------------------------------------------------
' Enum: Options
'--------------------------------------------------------------------
Public Enum ENUM_OPTIONS
'Main
eROW_OPTIONS_MAIN_AUTO_CLOSE = 2
eROW_OPTIONS_MAIN_AUTO_ASSIGN
eROW_OPTIONS_MAIN_SPARE_1
eROW_OPTIONS_MAIN_AUTO_RELAUNCH
'Assign
eROW_OPTIONS_ASSIGN_SPARE_1
'Task
eROW_OPTIONS_TASK_AUTO_CREATE_CHECKLIST
eROW_OPTIONS_TASK_AUTO_CREATE_PER_FOLDER
'General
eROW_OPTIONS_GENERAL_AUTO_RUN
eROW_OPTIONS_GENERAL_AUTO_LOAD_PI_LIST
eROW_OPTIONS_GENERAL_AUTO_LAUNCH_PXX
eROW_OPTIONS_GENERAL_AUTO_LAUNCH_RISK
eROW_OPTIONS_GENERAL_MANUALLY_SPARE_2
eROW_OPTIONS_GENERAL_SPARE_3
eROW_OPTIONS_GENERAL_SPARE_4
eROW_OPTIONS_GENERAL_USE_CHECKLIST
'Review
eROW_OPTIONS_REVIEW_AUTO_OPEN_ATTACHMENTS
eROW_OPTIONS_REVIEW_AUTO_COMPARE_CHECKLIST
eROW_OPTIONS_APPLICATION_RUNNING
eROW_COUNTRIES_UNITED_STATES
eROW_COUNTRIES_CHINA
eROW_COUNTRIES_AUSTRAILIA
eROW_COUNTRIES_GERMANY
eROW_COUNTRIES_JAPAN
eROW_COUNTRIES_UNITED_KINGDOM
eROW_COUNTRIES_BRAZIL
eROW_COUNTRIES_SWEDEN
End Enum
Last edited by FunkMonkey; Jun 5th, 2025 at 03:17 PM.
-
Jun 5th, 2025, 04:02 PM
#2
Re: [Index was outside the bounds of the array.] But it's not
It is very difficult to follow your business logic without some sort of minimal reproducible example. What I can suggest to you is to setup a breakpoint on the line that throws the exception then in your watch window see what the upper-bounds of the array are and compare them to the index that is trying to be accessed.
My suspicion is that you're not loading your spreadsheet into the multi-dimensional array like you expect it to and making the assumption the data fits.
-
Jun 5th, 2025, 04:12 PM
#3
Re: [Index was outside the bounds of the array.] But it's not
You’re aware VB.Net arrays are zero based?
A 2 element array contains an element at index 0 and an element at index 1
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 5th, 2025, 04:38 PM
#4
Thread Starter
Hyperactive Member
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by .paul.
You’re aware VB.Net arrays are zero based?
A 2 element array contains an element at index 0 and an element at index 1
It starts at (1), please see the capture of the array above. Also, to verify I just forced the Row to access Index (0) and I get an "Out of bounds" error message just to verify I was not missing something per your post.
Any other suggestions.
-
Jun 5th, 2025, 09:43 PM
#5
Re: [Index was outside the bounds of the array.] But it's not
What line does it break on, and what are the EXACT index values at that time?
Show the code it affects only…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 5th, 2025, 10:03 PM
#6
Thread Starter
Hyperactive Member
Re: [Index was outside the bounds of the array.] But it's not
The Code it breaks on is the first section above. I know that the return from the array is correct as I used a variable just before the break and it returned the correct boolean value. I have cut/paste a section of the code above for your convienence.
Code:
Dim x As Boolean = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_MAIN_AUTO_CLOSE, cCOL_START))
CK_AUTO_CLOSE_MAIN.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_MAIN_AUTO_CLOSE, cCOL_START))
The array information is also there in the original post but will repost it here.
Code:
(1, 1) "Default Option" Object {String}
(1, 2) "DO Setting" Object {String}
(1, 3) "Comment" Object {String}
(2, 1) "Main Auto Close" Object {String}
(2, 2) "True" Object {String}
(2, 3) "Closed the Tab if it has a ""Close"" button (After Updates)" Object {String}
(3, 1) "Main Auto Assign" Object {String}
(3, 2) "True" Object {String}
(3, 3) "Re-assigns the Main to the user" Object {String}
(4, 1) "Main Spare 1" Object {String}
(4, 2) False Object {Boolean}
(4, 3) "Spare bit" Object {String}
The strange thing is that it was working fine. Not sure what I did to break it, but the checkboxes won't load from the array. I did hardcode them, and they loaded all false did not try TRUE though.
Any thoughts?
-
Jun 6th, 2025, 12:30 AM
#7
Re: [Index was outside the bounds of the array.] But it's not
If VS tells you the index is outside of the bounds of the array, the chances are the index is outside of the bounds of the array.
I've mentioned this before about your code, but you're showing indices as one of millions of hard to read constants. If you want to find the cause of the error, put a breakpoint in your code there, run your code and then step through your code and check each variable or constant involved.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 6th, 2025, 08:18 AM
#8
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by FunkMonkey
It starts at (1), please see the capture of the array above. Also, to verify I just forced the Row to access Index (0) and I get an "Out of bounds" error message just to verify I was not missing something per your post.
Any other suggestions.
If you're getting an out of bounds exception at index 0, then that means your array isn't populated at all.
Last edited by dday9; Jun 6th, 2025 at 08:51 AM.
-
Jun 6th, 2025, 08:50 AM
#9
Re: [Index was outside the bounds of the array.] But it's not
In VB6, you could have 1 based arrays. You probably can in VBA, as well. In .NET, you have 0 based arrays and that is ALL you have. You can't alter that. If you think you are using 1-based arrays...you are mistaken. Of course, you can make a 0 based array and ignore the first element, which will look like a 1-based array, but it will have a different size.
It's as DDay stated, though: If you are finding nothing in the 0 element, then the array is empty, because there is no such thing as a 1-based array in .NET.
My usual boring signature: Nothing
 
-
Jun 10th, 2025, 05:46 AM
#10
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by Shaggy Hiker
In .NET, you have 0 based arrays and that is ALL you have. You can't alter that.
Actually, that's not true. You can create arrays in .Net with any lowerbound you desire:-
Code:
Dim my2DArr = Array.CreateInstance(GetType(String), {10, 10}, {1, 1})
The above code creates an 2D Integer array with a lower bound of (1,1).
I doubt this is what OP did though as very few .Net programmers are even aware you can do this.
-
Jun 10th, 2025, 05:57 AM
#11
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by Niya
Actually, that's not true. You can create arrays in .Net with any lowerbound you desire:-
Code:
Dim my2DArr = Array.CreateInstance(GetType(String), {10, 10}, {1, 1})
The above code creates an 2D Integer array with a lower bound of (1,1).
I doubt this is what OP did though as very few .Net programmers are even aware you can do this.
I thought there was a way. I was aware of that method on Feb 12th, 2014 Question is, Are you really that obsessive about array LowerBounds? It's just another way of clinging on to classic VB, even if it is more work creating and using them...
https://www.vbforums.com/showthread....=1#post4615349
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 10th, 2025, 06:57 AM
#12
Re: [Index was outside the bounds of the array.] But it's not
-
Jun 10th, 2025, 08:11 AM
#13
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by Niya
You'd be quite surprised. Linux vs Windows, VB6 vs VB.Net, iOS vs Android....those are nothing. Wait till you see an argument over 1-based vs 0-based indexing.....whoo boy
I have no doubt that there are people out there who are willing die for 1-based indexing. They will gut you and leave you to die in the street if you even suggest to them that 0 based indexing is better(which it is  ) 
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 10th, 2025, 11:00 AM
#14
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by Niya
Actually, that's not true. You can create arrays in .Net with any lowerbound you desire:-
Code:
Dim my2DArr = Array.CreateInstance(GetType(String), {10, 10}, {1, 1})
The above code creates an 2D Integer array with a lower bound of (1,1).
I doubt this is what OP did though as very few .Net programmers are even aware you can do this.
Well, I certainly didn't know that. In VB6 you had Option Base 1 (if I remember right), which may have been default.
I understand the argument over 1 based arrays...I just don't care about it. It alters the math in ways that some people find convenient while others find inconvenient.
My usual boring signature: Nothing
 
-
Jun 10th, 2025, 11:19 AM
#15
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by Shaggy Hiker
Well, I certainly didn't know that. In VB6 you had Option Base 1 (if I remember right), which may have been default.
Yes, Option Base.
 Originally Posted by Shaggy Hiker
I understand the argument over 1 based arrays...I just don't care about it. It alters the math in ways that some people find convenient while others find inconvenient.
Zero-based indexing is generally superior due to its mathematical simplicity and its alignment with how memory is addressed at the hardware level. The confusion often arises from the term "index", which implies a positional label rather than a memory offset. This framing leads to a flawed mental model when reasoning about arrays. In reality, an index represents the number of elements offset from the base address (i.e., the first element). Therefore, an index of 0 denotes a zero-offset, accessing the element located exactly at the base rather than implying a distinct "zeroth" element in a positional sense.
-
Jun 10th, 2025, 01:07 PM
#16
Thread Starter
Hyperactive Member
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by Niya
Yes, Option Base.
Zero-based indexing is generally superior due to its mathematical simplicity and its alignment with how memory is addressed at the hardware level. The confusion often arises from the term "index", which implies a positional label rather than a memory offset. This framing leads to a flawed mental model when reasoning about arrays. In reality, an index represents the number of elements offset from the base address (i.e., the first element). Therefore, an index of 0 denotes a zero-offset, accessing the element located exactly at the base rather than implying a distinct "zeroth" element in a positional sense.
Haven't been in this thread for a while, but I guess Microsoft's debugger must have a bug in it then because as seen below, the array starts at (1). this is a direct read from an Excel spreadsheet using Range. If it started at (0) based I would expect the array to start at (0) based. I know I have not programmed in C/C++ for a while now, but I would not think that Microsoft would change their debugger to start at index(1) when they mean index (0)?
Code:
(1, 1) "Default Option" Object {String}
(1, 2) "DO Setting" Object {String}
(1, 3) "Comment" Object {String}
(2, 1) "Main Auto Close" Object {String}
(2, 2) "True" Object {String}
(2, 3) "Closed the Tab if it has a ""Close"" button (After Updates)" Object {String}
(3, 1) "Main Auto Assign" Object {String}
(3, 2) "True" Object {String}
(3, 3) "Re-assigns the Main to the user" Object {String}
(4, 1) "Main Spare 1" Object {String}
(4, 2) False Object {Boolean}
(4, 3) "Spare bit" Object {String}
-
Jun 10th, 2025, 01:27 PM
#17
Re: [Index was outside the bounds of the array.] But it's not
Do me a favor and just give us the results of the following:
Code:
Console.WriteLine("Lower bounds of the first dimension: {0}", my2dArray.GetLowerBound(0))
Console.WriteLine("Upper bounds of the first dimension: {0}", my2dArray.GetUpperBound(0))
Console.WriteLine("Lower bounds of the second dimension: {0}", my2dArray.GetLowerBound(1))
Console.WriteLine("Upper bounds of the second dimension: {0}", my2dArray.GetUpperBound(1))
-
Jun 11th, 2025, 03:46 AM
#18
Re: [Index was outside the bounds of the array.] But it's not
You should do as dday asked, as it’s relevant to your problem…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2025, 10:15 AM
#19
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by Niya
Zero-based indexing is generally superior due to its mathematical simplicity and its alignment with how memory is addressed at the hardware level. The confusion often arises from the term "index", which implies a positional label rather than a memory offset. This framing leads to a flawed mental model when reasoning about arrays. In reality, an index represents the number of elements offset from the base address (i.e., the first element). Therefore, an index of 0 denotes a zero-offset, accessing the element located exactly at the base rather than implying a distinct "zeroth" element in a positional sense.
It is also worth noting that, "off by one" errors are so common in coding that they are the butt of jokes. When there is something that causes people to frequently make mental errors, then it's something worth thinking about.
My usual boring signature: Nothing
 
-
Jun 11th, 2025, 10:27 AM
#20
Re: [Index was outside the bounds of the array.] But it's not
My New Year's resolution is to stop making off-by-one errors.
So far, I'm off to a great start, having made only 0 errors this year!
-
Jun 11th, 2025, 10:35 AM
#21
Re: [Index was outside the bounds of the array.] But it's not
If the OP would post the code that actually reads the spreadsheet and populates the array that would probably help.
That being said, the OP hasn't stated if this error is still occurring or if it has been fixed. An Index Out of Bounds error should be a trivial problem to track down and fix. Do the values of the indices used when the error occurs match with the expectation of what they should be? If not, why not? Is it possible that events are causing your code to try to access the array before it has been populated?
Lastly, and this was touched on in another thread, but ENUM_PALOOZA makes it difficult to follow what code is doing. I'm not saying it is bad or good or that you need to change it, but for an outsider to look at it and offer help, it adds a level of complication that will likely make some people not bother trying to help.
-
Jun 11th, 2025, 07:25 PM
#22
Thread Starter
Hyperactive Member
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by dday9
Do me a favor and just give us the results of the following:
Code:
Console.WriteLine("Lower bounds of the first dimension: {0}", my2dArray.GetLowerBound(0))
Console.WriteLine("Upper bounds of the first dimension: {0}", my2dArray.GetUpperBound(0))
Console.WriteLine("Lower bounds of the second dimension: {0}", my2dArray.GetLowerBound(1))
Console.WriteLine("Upper bounds of the second dimension: {0}", my2dArray.GetUpperBound(1))
Here are the results. Told you it started at (1) but no one will listen.
Lower bounds of the first dimension: 1
Upper bounds of the first dimension: 27
Lower bounds of the second dimension: 1
Upper bounds of the second dimension: 3
So I'm accessing, or trying to, Row 2 Col 2. Should be no problems even if this did start at index (0).
EDIT: Here is a walk through of what is going on.....
[code]
Dim x As Boolean = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_MAIN_AUTO_CLOSE, cCOL_START))
CK_AUTO_CLOSE_MAIN.Checked = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_MAIN_AUTO_CLOSE, cCOL_START))
[/code
Because of the error I placed a variable to read the output. The output is TRUE, so the read from the array is correct.
Here is what the array GetOptionMember looks like.
Code:
Public Function GetSettingsMember(ByVal nRow As Integer, ByVal nCol As Integer) As String
GetSettingsMember = m_objSettings_arr(nRow, nCol)
End Function
Here is the excel sheet first couple of read items. They all match up, but the error still persists.
Code:
Default Option |DO Setting |Comment
Main Auto Close |TRUE |Closed the Tab if it has a "Close" button (After Updates)
Main Auto Assign |TRUE |Re-assigns the Main to the user
EDIT: For sanity sake I placed (x) as the input to the checkbox, but it still generated an error.
Code:
szErr = "Error occured for the following reason [Index was outside the bounds of the array.]"
Last edited by FunkMonkey; Jun 11th, 2025 at 07:53 PM.
-
Jun 11th, 2025, 07:28 PM
#23
Thread Starter
Hyperactive Member
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by OptionBase1
If the OP would post the code that actually reads the spreadsheet and populates the array that would probably help.
That being said, the OP hasn't stated if this error is still occurring or if it has been fixed. An Index Out of Bounds error should be a trivial problem to track down and fix. Do the values of the indices used when the error occurs match with the expectation of what they should be? If not, why not? Is it possible that events are causing your code to try to access the array before it has been populated?
Lastly, and this was touched on in another thread, but ENUM_PALOOZA makes it difficult to follow what code is doing. I'm not saying it is bad or good or that you need to change it, but for an outsider to look at it and offer help, it adds a level of complication that will likely make some people not bother trying to help.
Here is the code. Hope you see something, but this code has been working just fine.
Code:
Public Function LoadTab(ByVal strTab As String) As Object
Dim bStatus As Boolean
Dim rng As Excel.Range
Dim dataArray(,) As Object
'Dim Obj As Object
Try
EPIQ.Cursor = Cursors.WaitCursor
SelectExcelSheet(strTab)
If (GetIsDebug()) Then
Debug.Print("GetExcel [LoadTab Enter]")
End If
bStatus = True
rng = xlWS.UsedRange
'Get the items in the tab
dataArray = CType(rng.Value2, Object(,))
LoadTab = dataArray
'Get the items in the tab
'LoadTab = xlWS.Range(xlApp.Selection, xlApp.Selection.End(xlDown)).CurrentRegion
If (GetIsDebug()) Then
Debug.Print("GetExcel [LoadTab Exit]")
End If
Catch ex As Exception
Dim szErr As String
szErr = "Error occured for the following reason [" & ex.Message & "]"
If (GetIsDebug()) Then
Debug.Print(szErr)
End If
bStatus = False
LoadTab = Nothing
dataArray = Nothing
End Try
EPIQ.Cursor = Cursors.Default
End Function
Yes the error is still there. Have started working in another area of the code to see what replies I get.
-
Jun 11th, 2025, 09:59 PM
#24
Re: [Index was outside the bounds of the array.] But it's not
Ok. It’s unusual for VB to create a 1 based array, which was proven by debugging as suggested by dday.
The next step is to use reflection to iterate through all of your enums, outputting the name and value, in a similar way to what you used for the array bounds…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 12th, 2025, 08:41 AM
#25
Re: [Index was outside the bounds of the array.] But it's not
I went back to look at the original message. You said that the code keeps jumping to the catch.
Exception handling is great, but it can get in the way of tracking down something like this. I can't remember which version of VS you are using, so this may be out of date, but I think you are in a fairly recent version: Under Debug | Windows, there is an option for Exception Settings. By default, the Common Language Runtime Exceptions is probably not checked. The checkbox is one of those trinary boxes, and you probably have it either unchecked or 'partial'. Check the box.
What this does is that execution will break when the exception is thrown rather than just jumping down to the exception handler. This will allow you to identify exactly which line is throwing the exception. When you have that, you can look at the values in that line, and should be able to see why the array is out of bounds.
My usual boring signature: Nothing
 
-
Jun 12th, 2025, 09:28 AM
#26
Thread Starter
Hyperactive Member
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by Shaggy Hiker
I went back to look at the original message. You said that the code keeps jumping to the catch.
Exception handling is great, but it can get in the way of tracking down something like this. I can't remember which version of VS you are using, so this may be out of date, but I think you are in a fairly recent version: Under Debug | Windows, there is an option for Exception Settings. By default, the Common Language Runtime Exceptions is probably not checked. The checkbox is one of those trinary boxes, and you probably have it either unchecked or 'partial'. Check the box.
What this does is that execution will break when the exception is thrown rather than just jumping down to the exception handler. This will allow you to identify exactly which line is throwing the exception. When you have that, you can look at the values in that line, and should be able to see why the array is out of bounds.
Thanks Shaggy
-
Jun 12th, 2025, 11:42 AM
#27
Re: [Index was outside the bounds of the array.] But it's not
That's better than my suggestion. I was just going to get you to do Console.WriteLines after each read attempt until it failed.
-
Jun 13th, 2025, 11:14 AM
#28
Re: [Index was outside the bounds of the array.] But it's not
I'd still recommend debugging ALL of your Enum values. This exception is almost definitely because you have a variable, or more likely an Enum value, that is not what you're expecting it to be.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2025, 03:44 PM
#29
Thread Starter
Hyperactive Member
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by .paul.
I'd still recommend debugging ALL of your Enum values. This exception is almost definitely because you have a variable, or more likely an Enum value, that is not what you're expecting it to be.
It's not the ENUM's. I placed the (x), in the first post, as the input to the checkbox.checked = x, and it still did the catch. The (x) was True, and this still generated the error.
Last edited by FunkMonkey; Jun 13th, 2025 at 03:47 PM.
-
Jun 13th, 2025, 04:39 PM
#30
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by FunkMonkey
It's not the ENUM's. I placed the (x), in the first post, as the input to the checkbox.checked = x, and it still did the catch. The (x) was True, and this still generated the error.
Are you sure you don’t have your indices messed up… i.e…
YourArray(y, x) instead of yourArray(x,y)???
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2025, 04:42 PM
#31
Re: [Index was outside the bounds of the array.] But it's not
If x is type object, try…
Checkbox.Checked=CBool(x.ToString)
Where CheckBox is a valid control name
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2025, 05:41 PM
#32
Thread Starter
Hyperactive Member
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by .paul.
Are you sure you don’t have your indices messed up… i.e…
YourArray(y, x) instead of yourArray(x,y)???
No their not messed up. The results come back with the value they should. I have checked that, but I would not receive an error in this instance either way as I am calling myArray(2,2). This falls in the boundaries of the array. I wish it was that easy.
I was thinking once, if the GUI module was screwed up but then I realized VB compiles it on any changes and the main form works just fine. The form giving this issue is the Options form which is called from the Main Form.
I know somewhere Something was, or had to be changed, as it was working just fine then it stopped working on all checkboxes. Every other control on the form works just as it should.
-
Jun 13th, 2025, 05:52 PM
#33
Re: [Index was outside the bounds of the array.] But it's not
How do you show the Options form???
Is it …
Or…
Code:
Dim frm As New frmOptions
frm.Show
???
It makes much more difference than you’d think. In the first case, you could just use…
Code:
frmOptions.CheckBox1.Checked = CBool(x)
But if the form isn’t shown as the default instance (previous code) then….
Code:
frm.CheckBox1.Checked=CBool(x)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2025, 06:17 PM
#34
Thread Starter
Hyperactive Member
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by .paul.
How do you show the Options form???
Is it …
Or…
Code:
Dim frm As New frmOptions
frm.Show
???
It makes much more difference than you’d think. In the first case, you could just use…
Code:
frmOptions.CheckBox1.Checked = CBool(x)
But if the form isn’t shown as the default instance (previous code) then….
Code:
frm.CheckBox1.Checked=CBool(x)
Code:
Dim mySelection As New DLG_RUN_SELECTIION
'User select operation type
'mySelction.StartUpPosition = 1
mySelection.ShowDialog() 'vbModeless
If (mySelection.DialogResult = DialogResult.OK) Then
'If ((mySelection.GetRunOption() = GetRunOption()) And (mySelection.GetRunOption() > -1)) Then
' 'Disable the Run Type combobox
' UpdateRunControls(ENUM_RUN.eRUN_SELECT_RUN_OPTION_COMPLETE, "Please select a different option ...", "BTN_RUN_Click")
' InitializeProgressBar(0)
' mySelection.Dispose()
' Exit Sub
' 'Else
' 'UpdateRunControls(ENUM_RUN.eRUN_SELECT_RUN_OPTION_COMPLETE, cMSG_RUNNING, "BTN_RUN_Click")
'End If
SetRunOption(mySelection.GetRunOption())
'Close the selection window
mySelection.Dispose()
The call with (x) is from a boolean type (x). It is confirmed to be "True". I would not be surprised if it was just 1 checkbox, but it's all of them.
Code:
Dim x As Boolean = CBool(GetOptionMember(ENUM_OPTIONS.eROW_OPTIONS_MAIN_AUTO_CLOSE, cCOL_START))
CK_AUTO_CLOSE_MAIN.Checked = x
EDIT: when opening the Options form, I see the checkbox is checked. Been tracking down the Catch error and did not see it. Anyway, here is the Dlg in question.
Last edited by FunkMonkey; Jun 13th, 2025 at 06:21 PM.
-
Jun 13th, 2025, 06:27 PM
#35
Re: [Index was outside the bounds of the array.] But it's not
Typically, you’d pass the data in the constructor…
Code:
Dim mySelection As New DLG_RUN_SELECTIION([all of the current options to set initial values])
Then in the dialog..
Code:
Public Sub New(data as WhateverType)
CheckBox1.Checked=data(0).someBoolean
‘ Etc
End sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2025, 06:35 PM
#36
Re: [Index was outside the bounds of the array.] But it's not
You’d probably want to save data as a form (dialog) level variable, then make sure it contains all of your latest option data before setting your dialog DialogResult property to close the dialog, or to return as unchanged in the case of cancelling.
When returning after closing the dialog, you’d then deal with your options…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2025, 06:48 PM
#37
Thread Starter
Hyperactive Member
Re: [Index was outside the bounds of the array.] But it's not
 Originally Posted by .paul.
Typically, you’d pass the data in the constructor…
Code:
Dim mySelection As New DLG_RUN_SELECTIION([all of the current options to set initial values])
Then in the dialog..
Code:
Public Sub New(data as WhateverType)
CheckBox1.Checked=data(0).someBoolean
‘ Etc
End sub
That is not possible, there are a good 50-60 controls on this Dlgbox. There are 7 tabs with 4 or more controls on each of them. I pass the Main Form OptionsArr through a SetOptionsArr for the DLG.
-
Jun 13th, 2025, 06:51 PM
#38
Re: [Index was outside the bounds of the array.] But it's not
It's the .Net way... It's called Object Oriented Programming...
https://learn.microsoft.com/en-us/do...ed-programming
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2025, 06:57 PM
#39
Re: [Index was outside the bounds of the array.] But it's not
I've exhausted my ideas on this, but...
No further code will run in your main form, until you close the dialog
Code:
If (mySelection.ShowDialog() = DialogResult.OK) Then
' Any data that you want to grab from the dialog should be here
End If
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2025, 07:02 PM
#40
Re: [Index was outside the bounds of the array.] But it's not
I did warn you that my solution would look nothing like your solution. I'm not sure how you're passing and retrieving data to and from your dialog, but it's incorrect... Have a look here. I can't make it any simpler.
http://www.scproject.biz/Using%20Dialogs.php#bm11
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|