3 Replies - 11602 Views - Last Post: 06 October 2009 - 05:53 PM Rate Topic: -----

#1 Fred Easy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-October 09

Overload resolution failed because no accessible 'ReadLine' ac

Posted 06 October 2009 - 08:03 AM

Hello All,

My name is Jim & I am a complete newbie to VB (first programming class ever). I have been working on a assignment & I'm lost in the woods. I have developed this code that should read in data from a file and store in a Structured array. Most of it works but I'm getting an error that I don't understand & VB Help/Web sites are not making it any clearer to me. The file opens & displays into a List box, so I know that works, I just can't figure out how to read in the data & store it into the Structre array. Code is below.

Option Strict On
Imports System.IO

Public Class frmMain

	'Creat a Structure for the Customer Information
	Structure CustomerData														'Create the Customer Data structure
		Dim strLastName() As String											   'Holds Last Name in an array
		Dim strFirstName() As String											  'Holds First Name in an array
		Dim strStreetAddress() As String										  'Holds Street Address in an array
		Dim strCity() As String												   'Holds City in an array
		Dim strState() As String												  'Holds State in an array
		Dim strZipCode() As String												'Holds Zip Code in an array

		Dim intCustomerNumber() As Integer										'Holds Customer Number in an array
		Dim intTelephoneNumber() As Integer									   'Holds Telephone Number in an array

		Dim dtmDateOfLastPayment() As Date										'Holds the Date of Last Payment in an array
		Dim decAccountBalance() As Decimal										'Holds Account Balance in an array
	End Structure

	'Declare the Structure Variable as an array
	Dim custData As CustomerData												   'Structure Variable
	Dim customerInfo() As CustomerData
	Dim intCount As Integer = 0													'Loop Counter
	Dim strFilename As String = "customerinfo.dat"								 'Declare strFilename = "customerinfo.dat" file

	Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



THIS IS THE SECTION THAT IS DENTING MY HEAD
Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click

		'Open the Text file that holds Customer Information Data
		'Dim CustomerInfoDataFile As StreamWriter
		Dim inputfile As StreamReader
		Dim strInput As String

		'Display the OpenDialog Box to read file data
		If ofdOpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
			MessageBox.Show(ofdOpenFileDialog1.FileName)

			If File.Exists(ofdOpenFileDialog1.FileName) Then
				'Open the file
				inputfile = File.OpenText(ofdOpenFileDialog1.FileName)

				Do Until inputfile.Peek = -1
					strInput = inputfile.ReadLine()
					lstDataFileRead.Items.Add(strInput)
				Loop
				'inputfile.Close()

				'Read the Customer Data from the file & store it in a array
				intCount = 0
				Do
					ReDim customerInfo(intCount + 1)
					'customerInfo(intCount).strLastName = 


					customerInfo(intCount).strLastName = inputfile.ReadLine(intCount)
					customerInfo(intCount).strFirstName = inputfile.ReadLine(intCount)
					customerInfo(intCount).intCustomerNumber = inputfile.ReadLine(intCount)
					customerInfo(intCount).strStreetAddress = inputfile.ReadLine(intCount)
					customerInfo(intCount).strCity = inputfile.ReadLine(intCount)
					customerInfo(intCount).strState = inputfile.ReadLine(intCount)
					customerInfo(intCount).strZipCode = inputfile.ReadLine(intCount)
					customerInfo(intCount).intTelephoneNumber = inputfile.ReadLine(intCount)
					customerInfo(intCount).decAccountBalance = inputfile.ReadLine(intCount)
					customerInfo(intCount).dtmDateOfLastPayment = inputfile.ReadLine(intCount)
					intCount = intCount + 1
				Loop
			Else
				MessageBox.Show(ofdOpenFileDialog1.FileName & " does not exist.")
			End If
		Else
			MessageBox.Show("You have not selected a file.")

		End If

		'Close the file when done.
		inputfile.Close()

	End Sub


Can someone point out what I am doing wrong? The text file that I'm trying to read in looks like this:

Test 01
Test 02
1234567890
Test 03
Test 04
MI
48088
1234567890
1000
10/05/09
 
Test 01
Test 02
1234567890
Test 03
Test 04
MI
48088
1234567890
1000
10/06/09
 
Test 01
Test 02
1234567890
Test 03
Test 04
MI
48088
1234567890
1000
10/07/09
 
Test 01
Test 02
1234567890
Test 03
Test 04
MI
48088
1234567890
1000.99
10/08/09
 
Test 01
Test 02
1234567890
Test 03
Test 04
MI
48088
1234567890
1000.01
10/08/09
 
Easy
Fred
123123123
123 That Away Street
Troy
MI
48083
1234567890
.12
10/05/2009
 
Jean
Billy
0983456
123 Not My Lover
Hollywood
CA
90210
4561237890
10,00000.91
10/05/09
 
Gaddis
Tony
45678902220
1492 Columbus Sales 
Austin
TX
98709
9781234567
2200.37
10/07/09
 
Irvine
Kip
6789
1 Wrong Way Drive
Dallas
TX
34567
3132222100
34.99
10/07/09
 
Irvine
Kip
6789
1 Wrong Way Drive
Dallas
TX
34567
3132222100
34.99
10/07/09
 
Cleveland
Grover
1600
1600 Pencel Head Street
Washington
D.C.
45678
3216540987
1000000
10/07/09
 
Boys
Pep
4538210956037509987
789 Gratiot Ave.
Roseville
MI
48085
1234567890
100000000000.03
10/05/2009
 
Boys
Pep
4538210956037509987
789 Gratiot Ave.
Roseville
MI
48085
1234567890
11.97
10/05/2009
 



Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Overload resolution failed because no accessible 'ReadLine' ac

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,468
  • Joined: 29-May 08

Re: Overload resolution failed because no accessible 'ReadLine' ac

Posted 06 October 2009 - 08:11 AM

First I've moved your post because what your programming is vb.net.
Secondly I've edited your post slightly to reveal the section we your experiencing the problem.

Finally could you post your question in the body of the post as the subtitle has cut it short.
Was This Post Helpful? 0
  • +
  • -

#3 Fred Easy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-October 09

Re: Overload resolution failed because no accessible 'ReadLine' ac

Posted 06 October 2009 - 10:36 AM

View PostAdamSpeight2008, on 6 Oct, 2009 - 07:11 AM, said:

First I've moved your post because what your programming is vb.net.
Secondly I've edited your post slightly to reveal the section we your experiencing the problem.

Finally could you post your question in the body of the post as the subtitle has cut it short.



THank you for movong my msg to the correct forum.

The Error msg is this:

Error 1 Overload resolution failed because no accessible 'ReadLine' accepts this number of arguments. E:\School\ITCS-1230-V0850 Visual Basic Programming\VB Projects\Wk 06 - PC 9-11\Wk 06 - PC 9-11\frmMain.vb 239 58 Wk 06 - PC 9-11
Was This Post Helpful? 0
  • +
  • -

#4 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Overload resolution failed because no accessible 'ReadLine' ac

Posted 06 October 2009 - 05:53 PM

View PostFred Easy, on 6 Oct, 2009 - 09:36 AM, said:

Overload resolution failed because no accessible 'ReadLine' accepts this number of arguments.


Imagine we have:

Sub MySub()
' Whatever...
End Sub


We "overload" this sub when we add another sub with the same name, but which accepts different arguments:

Sub MySub(name As String)
' ...
End Sub


We now say that MySub is overloaded - it just means that it has more than one definition.

At runtime - i.e. when you run the program - the CLR (the part of the .Net framework that runs the program) - has to decide which version of the sub it should call. It does this by looking at the argumetns that you have supplied. If you supply no arguments, then it will call MySub(). If you supply a String, then it will call MySub(name As String). If you supply something else, then you get an error message very similar to your message. It just means that it could not decide which sub or function (method) it was supposed to call from the choices available.

How can we know what overloads of StreamReader.ReadLine exist?
- Just look in the library. You start at StreamReader and then look at "all members".

Let's first see a function that has a humungous number of overloads:
http://msdn.microsof....drawimage.aspx

Wow - 30 overloads. (The people who designed the framework think they made a mistake here - far too many overloads. But because it shipped in v1.0 of the framework, we've been stuck with them ever since).

If you look at the methods of StreamReader:
http://msdn.microsof...er_methods.aspx

You can see that ReadLine has no overloads. Compare it to the Read method:
Read -- Overloaded. Reads the next character or next set of characters from the input stream.
ReadLine -- Reads a line of characters from the current stream and returns the data as a string.


And what arguments does ReadLine accept?
http://msdn.microsof...r.readline.aspx

The answer is none. It is like MySub() - it does not accept any arguments.

Therefore the problem with your code is that you send it an argument - intCount when there is no such overload of the function.

customerInfo(intCount).strLastName = inputfile.ReadLine(intCount)

Should be

customerInfo(intCount).strLastName = inputfile.ReadLine()

Readline works by keeping track of the location in the file. Call it the first time, it reads the first line. Call it again, it reads the next line. Eventually there are no more lines, and it returns Nothing.
Was This Post Helpful? 1

Page 1 of 1