IndexOutOfRangeException



Programming Help Forums
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



IndexOutOfRangeException Expand / Collapse
Author
Message
Posted 5/7/2009 11:13:53 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 5/8/2009 12:35:05 PM
Posts: 2, Visits: 5
I'm having issues coding a project program for my class. It's supposed to be a program for a book publisher.

After trying to utilize the streamreader object and put the information into an array, I keep getting the Message "Index outside the bounds of the array." My array contains the correct number of elements and everything. I tried using the "Step Into" feature of Visual Studio, but it still didn't help us to find the problem. I will copy and paste the code here, but am unable to attach the zip file that I created because of an error with the server. know that this is my first post, but I'm not going to be a "hit-and-run" poster because I'm planning on taking several more VB classes in the upcoming semesters. This project is due at midnight tonight so I'm extremely worried that I won't be able to figure the problem out!

Thank you very much for the help!

Ross

[font=Arial]Code Begins Below[/font]



' Program Name: Flick's Book Publishing
' Author: Robert Wardrup
' Date: 5 May,2009
' Purpose: This windows application determines the total books on hand,
' the total books on order, the total retail value of books on
' hand and on order.


Option Strict On

Public Class frmFlicks

'Class Level Private Variables
Public Shared _intSizeOfArray As Integer = 17
Public Shared _strInventoryItem(_intSizeOfArray) As String
Private _strItemId(_intSizeOfArray) As String

Private Sub frmFlicksPublish_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' The frmFlicksPublish load event reads the inventory text file and
' fills the listbox object with the inventory items.

'Initialize an instance of the streamreader object and declare variables
Dim objReader As IO.StreamReader
Dim strLocationAndNameOfFile As String = "G:\VBasic\CP 9\Flick's Fictional Book Publishing\Flick's Fictional Book Publishing\warehouse.txt"
Dim intCount As Integer = 0
'Dim intFill As Integer
Dim strFileError As String = "The file is not available. Restart when the file is available."

'Verify the file exists
If IO.File.Exists(strLocationAndNameOfFile) = True Then
objReader = IO.File.OpenText(strLocationAndNameOfFile)
'Read the file line by line until the file is completed.
Do While objReader.Peek <> -1
_strInventoryItem(intCount) = objReader.ReadLine()
_strItemId(intCount) = objReader.ReadLine()
intCount += 1
Loop
objReader.Close()

' The ListBox object is filled with IDs
For intFill = 0 To 16
Me.lstBooks.Items.Add(_strItemId(intFill))
Next
Else
MsgBox(strFileError, , "Error")
Me.Close()
End If
End Sub

Private Sub btnComputeInventory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComputeInventory.Click
' The btnComputeInventory click event calls the Compute sub procedures
'Declare Variables
Dim intTotalBooksOnHand As Integer
Dim intTotalBooksOnOrder As Integer
Dim decTotalCostBooksHand As Decimal
Dim decTotalCostBooksOrder As Decimal
End Sub
End Class
Post #3600
Posted 5/8/2009 8:02:25 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 11/11/2009 6:46:14 PM
Posts: 83, Visits: 111
Did you get it figured out in time?
Post #3615
Posted 5/8/2009 9:06:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 5/8/2009 12:35:05 PM
Posts: 2, Visits: 5
Not yet, I just sent him what I had finished and am hoping that he'll take it late when I do figure it out.. since he couldn't figure it out either.
Post #3616
Posted 4/1/2010 11:06:59 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 4/2/2010 12:10:02 AM
Posts: 1, Visits: 3
Did you ever figure this out? Could you post the code?

Joylene
Post #5180
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: ProgrammingHelp, Viral Unity, Matt.Hill, DaveL, Alex.D

Permissions Expand / Collapse

All times are GMT -5:00, Time now is 9:34am

Powered By InstantForum.NET v4.1.4 © 2012
Execution: 0.359. 18 queries. Compression Disabled.