473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Array out of bounds Visual Basic

I am trying to calculate the price of a pizza based on the following table.

Expand|Select|Wrap|Line Numbers
  1.               Small   Medium  Large  Monster
  2. Regular       5.99    6.99    7.99    8.99
  3. Stuffed Crust 7.99    8.99    9.99   10.99
I am using a two dimensional array and the following code. I am getting an array out of bounds error. Can anyone help? Thanks in advance!

Expand|Select|Wrap|Line Numbers
  1. Dim pizzaArrayDecimal(,) As Decimal = {{5.99, 6.99, 7.99, 8.99}, _
  2.                                   {7.99, 8.99, 9.99, 10.99}}
  3.  
  4.  
  5.     Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
  6.         'Look up the pizza price
  7.  
  8.         Dim SizeIndexInteger As Integer
  9.         Dim StyleIndexInteger As Integer
  10.  
  11.         SizeIndexInteger = cboSize.SelectedIndex
  12.         StyleIndexInteger = cboStyle.SelectedIndex
  13.  
  14.         If SizeIndexInteger <> -1 And StyleIndexInteger <> -1 Then
  15.             pizzaTextBox.Text = pizzaArrayDecimal(SizeIndexInteger, StyleIndexInteger).ToString("N")
  16.         Else
  17.             MessageBox.Show("Select the Size and Style.", "Information Missing", _
  18.             MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  19.  
  20.         End If
  21.     End Sub
May 2 '11 #1
1 1761
Killer42
8,435 Expert 8TB
Hi.

Apologies for the delay.

From the look of the syntax, this probably belongs in the VB.Net area. And given that it's been over a month, you've probably figured it out by now.

In any case, I'd hazard a guess that your problem centres around whether your array and your combo box start counting at 0 or 1. Depending on which is which, you're probably bombing on an index value of either 0 or 4. It should be a simple matter of either changing your array definition, or adjusting the index values up or down by 1 before accessing the array.
Jun 16 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: agascoig | last post by:
I am just starting to learn Java J2RE 5.0. I coded the matrix library below and found that the array accessing is really slow since each access is checked: ...
54
by: seberino | last post by:
Many people I know ask why Python does slicing the way it does..... Can anyone /please/ give me a good defense/justification??? I'm referring to why mystring gives me elements 0, 1, 2 and 3...
5
by: K. Shier | last post by:
when attempting to edit code in a class file, i see the bug "Visual Basic ..NET compiler is unable to recover from the following error: System Error &Hc0000005&(Visual Basic internal compiler...
6
by: Flip | last post by:
I'm reading the O'Reilly's Progamming C# book and I have a question about array bounds checking. On page 174, near the top, they show an example where c# does indeed to array bounds checking cause...
1
by: noleander | last post by:
Hey. I'm new to Visual C++. I've got a large application, and I need to make sure all array accesses are within bounds. Back on Unix we had a tool called Purify that detected array-out-of-bounds...
2
by: JOSE RIVAS | last post by:
HI PLEASE HELP Im making a program, that makes a process (OCR process) so i reach to automate it in order to open a file ("c:\image.bmp") and then executes the ocr process ok.. it is working...
9
by: Joe | last post by:
hi. simple question: how can one declare Array (or table) with unknown number of elements, and then assign values to it, example: Dim TableStrings() as String TableStrings(0) = "first value"...
6
by: ashokbio | last post by:
I want to create an associative array, similar to PERL language, using Visual Basic 6. Example: Using PERL %A = ("A"=>"Apple","B"=>"Banana"); i.e., A is associated to the word Apple and B...
3
by: Sludge | last post by:
Hi! I am brand new here. I am extracting data from a database table in access and then populating an array in visual basic (VBA in access currently). I would like to reformat this array and...
6
by: Vince | last post by:
Hello all, I am using Visual Basic to open a saved query and then save information in the query to an array for later use. The problem is that the same query shows different results when opened...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.