How to get content from a text file into a listbox using an array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stacey Prahl
    New Member
    • Nov 2010
    • 4

    How to get content from a text file into a listbox using an array?

    Option Strict On
    Public Class frmBookPublishi ng

    ' Class Level Private Variables
    Private Shared _intSizeOfArray As Integer = 16
    Private Shared _strWarehouseIt em(_intSizeOfAr ray) As String
    Private _decBookPrice(_ intSizeOfArray) As Decimal
    Private _intBooksOnHand (_intSizeOfArra y) As Integer
    Private _intBooksOrdere d(_intSizeOfArr ay) As Integer

    Private Sub frmBookPublishi ng_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
    ' The frmBookPublishi ng load event reads the warehouse text file and fills the ListBox object
    ' with the warehouse items.
    ' Initialize an instance of the Streamreader object and declare variables.
    Dim objReader As IO.StreamReader
    Dim strLocationAndN ameofFile As String = "C:\Users\Stace y\Documents\Vis ual Studio 2008\Projects\F licksBookPublis hing\FlicksBook Publishing\File \warehouse.txt"
    Dim intCount As Integer = 0
    Dim strFileError As String = "The file is not available. Restart when the file is available."
    ' Verify the file exists
    If IO.File.Exists( strLocationAndN ameofFile) Then
    objReader = IO.File.OpenTex t(strLocationAn dNameofFile)
    'Read the file line by line until the file is completed
    Do While objReader.Peek <> -1
    _strWarehouseIt em(intCount) = objReader.ReadL ine()
    _decBookPrice(i ntCount) = Convert.ToDecim al(objReader.Re adLine())
    _intBooksOnHand (intCount) = Convert.ToInt32 (objReader.Read Line())
    intCount += 1
    _intBooksOrdere d(intCount) = Convert.ToInt32 (objReader.Read Line())
    intCount += 1
    Loop
    objReader.Close ()

    ' Display the Names of the Books
    For intFill = 0 To (_strWarehouseI tem.Length - 1)
    Me.lstBookTitle s.Items.Add(_st rWarehouseItem( intFill))
    Next
    Else
    MsgBox(strFileE rror, , "Error")
    Me.Close()
    End If
    End Sub
    Attached Files
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    This is not VB6.
    If it is VB.net, please redirect it to that forum.

    Comment

    • Stacey Prahl
      New Member
      • Nov 2010
      • 4

      #3
      Sorry about that.

      Comment

      • Stacey Prahl
        New Member
        • Nov 2010
        • 4

        #4
        I clicked on the VB.Net to ask a question. I guess I did something wrong. Anyway, after having read the guidelines, my post is not applicable for answer, I was seeking assistance for a homework problem.

        Comment

        Working...