How to display an arrays' contents into a listbox?

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

    #1

    How to display an arrays' contents into a listbox?

    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 Publi shing\File\ware house.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( intFi ll))
    Next
    Else
    MsgBox(strFileE rror, , "Error")
    Me.Close()
    End If
    End Sub
Working...