473,399 Members | 3,832 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,399 software developers and data experts.

Open a file, read text and display in a listbox

Hi, I am very new to programming and have just started to use Visual Basic 2005 Express Edition. I am trying to read from a text file to draw a rectangles and lines. However to begin I'm trying to get the information to show in a listbox so that I know the application is reading the file correctly. I seem to be able to open the file but it doesn't display anything in the listbox.
Expand|Select|Wrap|Line Numbers
  1. Dim FileName As String
  2.         Dim reader As System.IO.StreamReader
  3.  
  4.         uieOpenFileDialog.InitialDirectory = "C:\"
  5.         uieOpenFileDialog.Title = "Open a File"
  6.         uieOpenFileDialog.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
  7.         uieOpenFileDialog.ShowDialog()
  8.  
  9.         MsgBox(FileName)
  10.         Dim DidWork As Integer = uieOpenFileDialog.ShowDialog()
  11.         If DidWork = DialogResult.Cancel Then
  12.             MsgBox("Cancel Button Clicked")
  13.         Else
  14.             FileName = uieOpenFileDialog.FileName
  15.             MsgBox(FileName)
  16.         End If
  17.  
  18.         reader = System.IO.File.OpenText(uieOpenFileDialog.FileName)
  19.         Dim shape As String
  20.         Dim code As Integer
  21.  
  22.         Try
  23.             Me.ListBox1.Items.Clear()
  24.  
  25.             Do While reader.Peek <> -1
  26.                 shape = reader.ReadLine
  27.                 If shape = "Rectangle" Then
  28.                     Select Case code
  29.                         Case 1
  30.  
  31.                             rect.X = Convert.ToInt32(reader.ReadLine)
  32.                             rect.Y = Convert.ToInt32(reader.ReadLine)
  33.                             rect.Width = Convert.ToInt32(reader.ReadLine)
  34.                             rect.Height = Convert.ToInt32(reader.ReadLine)
  35.  
  36.                             ListBox1.Items.Add()
  37.  
  38.  
  39.                         Case 2
  40.                             rect.X = Convert.ToInt32(reader.ReadLine)
  41.                             rect.Y = Convert.ToInt32(reader.ReadLine)
  42.                             rect.Width = Convert.ToInt32(reader.ReadLine)
  43.                             rect.Height = Convert.ToInt32(reader.ReadLine)
  44.  
  45.                             ListBox1.Items.Add
  46.  
  47.                     End Select
  48.                 Else
  49.                 End If
  50.             Loop
  51.         Catch
  52.             Me.ListBox1.Items.Add("file is empty")
  53.         End Try
  54.         reader.Close()
  55.     End Sub
The error code I'm receiving is: Error 1 Argument not specified for parameter 'item' of 'Public Function Add(item As Object) As Integer'.
Sep 15 '08 #1
2 6109
Teme64
10
You should add something to ListBox when you're using Add method (lines 36 and 45). Change lines to following:

Expand|Select|Wrap|Line Numbers
  1. ListBox1.Items.Add("Code=" & code &  ", Rect.X=" & rect.X & ", Rect.Y=" & rect.Y & ", Rect.Width=" & rect.Width & ", Rect.Height=" & rect.Height)
  2.  
and you'll see what you read from your file.
Sep 15 '08 #2
Hi friend.

Give a example of the line you have in this file text this way I could help you.

Your code is missing information. For example:

shape = reader.ReadLine
If shape = "Rectangle" Then
Select Case code *******You never put any value in code always is 0 (zero)
Case 1
****Convert the same value in this 4 lines. This will give you a DOT on screen
rect.X = Convert.ToInt32(reader.ReadLine)
rect.Y = Convert.ToInt32(reader.ReadLine)
rect.Width = Convert.ToInt32(reader.ReadLine)
rect.Height = Convert.ToInt32(reader.ReadLine)

ListBox1.Items.Add()


Case 2
rect.X = Convert.ToInt32(reader.ReadLine)
rect.Y = Convert.ToInt32(reader.ReadLine)
rect.Width = Convert.ToInt32(reader.ReadLine)
rect.Height = Convert.ToInt32(reader.ReadLine)

***here you are adding nothing to the listbox1
ListBox1.Items.Add

End Select
Else
End If

Put here a line of the text file that I'll help you.

Rogerio
Sep 15 '08 #3

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

Similar topics

6
by: Roy Riddex | last post by:
I have a text file which holds data for 30 cars in the following way: CarRegistration CarType CarClass Available I'm trying to display the full contents of this...
4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or...
2
by: Light | last post by:
Hi I am a relatively inexperienced and I need help in this, what seems to be a simple task I am trying to read from a text file which contains a list of peoples names in the format 'Surname...
2
by: Sin | last post by:
Hello everyone, I'm totally stumped at how little info I can find in MSDN or on the web concerning this. It's almost as if only microsoft personel hold the key to these secrets or something!!! ...
4
by: Daniel Kaseman | last post by:
I want to make a program that has 3 textboxes for inputting: Name, ID, Amount, and then when I click "Add Item" button, it adds it to a text file, and shows up on the list box. When I close and...
9
by: Suman | last post by:
Happy Friday everyone!!! I am working on a windows service and a C# application and needed some help with certain functionality. Please read through my issue below. Thanks! I have a windows...
2
by: rn5a | last post by:
Using the FileSystemInfo class, I am retrieving all the directories & files existing in a particular directory on the server & listing them in a ListBox. If an item in the ListBox happens to be a...
6
by: kimiraikkonen | last post by:
Hi, I want to save all the item content of a listbox line by line into a simple text file then recall them when my project is opened. For example listbox1 contains: That - item1 Group ...
1
by: iftekar14 | last post by:
i have to create this at VB express 2008 When the user clicks the Process Files button, do the following: Read and process the contents of each of the 6 files. Each file contains data in a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.