11 Replies - 1277 Views - Last Post: 02 December 2015 - 09:53 AM Rate Topic: -----

#1 Vyise  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-December 15

Program pulling information from a text file but not populating

Posted 01 December 2015 - 01:20 PM

I am a new student in a VB class we are working on a program that should pull information from a text file then populate it into a list box. It is not displaying in the list box and it isn't throwing any errors. I have tried moving the files, different machines, nothing works. What is really odd is the instructor copy of this code doesn't work ether having the same problem. I am just hoping someone can at least point me in the right direction to getting this code to work.

  Option Strict On
Public Class frmDepreciation
    ' Class Level Variables

    Private _intLifeOfItems As Integer = 5
    Public Shared _intSizeOfArray As Integer = 7
    Public Shared _strInventoryItem(_intSizeOfArray) As String
    Private _strItemID(_intSizeOfArray) As String
    Private _decInitialPrice(_intSizeOfArray) As Decimal
    Private _intQuantity(_intSizeOfArray) As Integer

    Private Sub frmDepreciation_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' This load event reads the inventory text file and populates the listbox with the items

        ' start an instance of StreamReader and declare variables
        Dim objReader As IO.StreamReader
        Dim strLocationAndNameOfFile As String = "filelocation"
        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 file Exists
        If IO.File.Exists(strLocationAndNameOfFile) 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()
                _decInitialPrice(intCount) = Convert.ToDecimal(objReader.ReadLine())
                _intQuantity(intCount) = Convert.ToInt32(objReader.ReadLine())
                intCount += 1
            Loop
            objReader.Close()
            ' The ListBox object is filled with the Inventory IDs
            For intFill = 0 To (_strItemID.Length - 1)
                lstInventoryID.Items.Add(_strItemID(intFill))
            Next
        Else
            MsgBox(strFileError, , "Error")
            Close()
        End If
    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Program pulling information from a text file but not populating

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13554
  • View blog
  • Posts: 54,094
  • Joined: 12-June 08

Re: Program pulling information from a text file but not populating

Posted 01 December 2015 - 01:31 PM

Wrap that all in a try/catch. I am thinking you are getting an error when you add 'nothing' to the list's items collection.

36	                lstInventoryID.Items.Add(_strItemID(intFill))

Was This Post Helpful? 0
  • +
  • -

#3 Vyise  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-December 15

Re: Program pulling information from a text file but not populating

Posted 01 December 2015 - 01:35 PM

No errors thrown. Program starts up like nothing is wrong just doesn't output anything into the list box.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13554
  • View blog
  • Posts: 54,094
  • Joined: 12-June 08

Re: Program pulling information from a text file but not populating

Posted 01 December 2015 - 01:38 PM

Then put a breakpoint at the top of the function and step through it.

When I ran it - again using a try/catch to wrap it all - with a list of only one items it threw an exception at that line I highlighted.

Perhaps explain what file you are using, where you have it located, etc.
Was This Post Helpful? 0
  • +
  • -

#5 Vyise  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-December 15

Re: Program pulling information from a text file but not populating

Posted 01 December 2015 - 01:45 PM

The text file look like this
Point of Sale Register
A101
1599.99
12
Store Display Racks
D208
49.99
112
this repeats a few dozen times
with the 1st line being the item name 2nd line is the item ID 3rd line is the value and 4th line is the quantity. The program is supposed to read through them and assign each one into the correct variable that is then displayed in the list box. That is why is loops every 4 lines assigning the variable as it goes. The 2nd variable is the one I am currently working one. I assume once I can get this one to display the others will fallow suit.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13554
  • View blog
  • Posts: 54,094
  • Joined: 12-June 08

Re: Program pulling information from a text file but not populating

Posted 01 December 2015 - 01:47 PM

So, again, put a break point at the top of the method and step through the lines. Examine what is happening.

Basic Debugging
Was This Post Helpful? 0
  • +
  • -

#7 Vyise  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-December 15

Re: Program pulling information from a text file but not populating

Posted 02 December 2015 - 09:21 AM

OK so I see that it is throwing a "Item = In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user." error. What would be the best why to fix this issue? From my understanding VB doesn't understand what information I am pointing to I just don't understand how to specify what it need to pull form.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13554
  • View blog
  • Posts: 54,094
  • Joined: 12-June 08

Re: Program pulling information from a text file but not populating

Posted 02 December 2015 - 09:24 AM

What line is it happening on?
Please copy/paste the entire error message.
Was This Post Helpful? 0
  • +
  • -

#9 Vyise  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-December 15

Re: Program pulling information from a text file but not populating

Posted 02 December 2015 - 09:28 AM

I put a point break on the
   For intFill = 0 To (_strItemID.Length - 1)
                    Me.lstInventoryID.Items.Add(_strItemID(intFill)) 

And when I stepped through it step by step it was under the .Items

That is the full error it is showing me. I am sorry I am fairly new at this.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13554
  • View blog
  • Posts: 54,094
  • Joined: 12-June 08

Re: Program pulling information from a text file but not populating

Posted 02 December 2015 - 09:34 AM

Okay - so inspect your items. Is '_strItemID(intFill)' a thing? Is the 'intFill' outside the bounds of an array? Is that important to this assignment (since the while loop to read in items can over run the length of the array so I am unclear).
Was This Post Helpful? 0
  • +
  • -

#11 Vyise  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-December 15

Re: Program pulling information from a text file but not populating

Posted 02 December 2015 - 09:50 AM

I have a watch on the the _strItemID and it is holding the data that I need to to output. But for some reason it isn't displaying it in the listbox. That intFill is just what was in the book removing does nothing for the problem.
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13554
  • View blog
  • Posts: 54,094
  • Joined: 12-June 08

Re: Program pulling information from a text file but not populating

Posted 02 December 2015 - 09:53 AM

I would certainly hope it is doing something. If you want to access an item in an array you need an index value. If 'intFill' is your loop control variable to tell you what index you are on.. then I would wager it is important.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1