473,320 Members | 2,080 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,320 software developers and data experts.

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

Option Strict On
Public Class frmBookPublishing

' Class Level Private Variables
Private Shared _intSizeOfArray As Integer = 16
Private Shared _strWarehouseItem(_intSizeOfArray) As String
Private _decBookPrice(_intSizeOfArray) As Decimal
Private _intBooksOnHand(_intSizeOfArray) As Integer
Private _intBooksOrdered(_intSizeOfArray) As Integer

Private Sub frmBookPublishing_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' The frmBookPublishing 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 strLocationAndNameofFile As String = "C:\Users\Stacey\Documents\Visual Studio 2008\Projects\FlicksBookPublishing\FlicksBookPubli shing\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(strLocationAndNameofFile) Then
objReader = IO.File.OpenText(strLocationAndNameofFile)
'Read the file line by line until the file is completed
Do While objReader.Peek <> -1
_strWarehouseItem(intCount) = objReader.ReadLine()
_decBookPrice(intCount) = Convert.ToDecimal(objReader.ReadLine())
_intBooksOnHand(intCount) = Convert.ToInt32(objReader.ReadLine())
intCount += 1
_intBooksOrdered(intCount) = Convert.ToInt32(objReader.ReadLine())
intCount += 1
Loop
objReader.Close()

' Display the Names of the Books
For intFill = 0 To (_strWarehouseItem.Length - 1)
Me.lstBookTitles.Items.Add(_strWarehouseItem(intFi ll))
Next
Else
MsgBox(strFileError, , "Error")
Me.Close()
End If
End Sub
Attached Files
File Type: txt warehouse.txt (591 Bytes, 282 views)
File Type: zip FlicksBookPublishing.zip (157.2 KB, 90 views)
Nov 29 '10 #1

✓ answered by Guido Geurs

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

3 2300
Guido Geurs
767 Expert 512MB
This is not VB6.
If it is VB.net, please redirect it to that forum.
Nov 29 '10 #2
Sorry about that.
Nov 29 '10 #3
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.
Nov 29 '10 #4

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

Similar topics

1
by: Scott | last post by:
I am new to perl, and have not found any good examples of parsing to help me out. I have a text file that I am reading into an array that has to be parsed out and put into another file. I have not...
6
by: Deano | last post by:
I needed to have a listbox populated by locations which are stored in tblLocations. However I wanted an "All locations" entry to be at the top of the listbox. This is not in the tblLocations. The...
1
by: Jeroen | last post by:
Hi, I am trying to get the lines of a text file into an array. Can anyone help me with some code to do this in VB.net? Greetings, Jeroen
1
by: Genevieve | last post by:
I have this text file below saved in my c: directory FeedA:100:200:400:233:564:10:237200:400:233 FeedB:267:126:548:128:675:16:293:567:89 FeedC:162:654:876:918:727:81:891:75:554...
1
by: sachin10 | last post by:
hi i m sachin, i m new to VB programming.i face some problem regarding the sorting of text file contents using arrays.text file have data in the format as below seq...
1
by: vjunkl | last post by:
Hello, I have a content text file in my project and I'd like to copy it to a folder at some point in the execution of the application(not during a build). If this is not possible, how about...
1
by: aarthi28 | last post by:
Hi, I have a text file "test.txt" that contains a series of 0's and 1's. For example, 0000001000010100011000 I need to read these values into an array so that i can perform a comparison with...
1
by: supahsain | last post by:
I got this assignment, and almost have no clue, and my teacher doesn't even teaches us anything This is what i am suppose to do...
4
by: Prisms | last post by:
I am trying to read a text file into an array and I'm having some trouble doing so. here is the code that I have so far. Any help would be much appreciated. #include <stdio.h> #include...
1
by: Jah Mason | last post by:
"Numbers.txt" 1 3 5 4 2 /*Currently i have functionality for a user to choose a number of values to be entered into an array, add numbers into the array "numbers" and process the mean, range,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: 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)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.