Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i am having this code for reading all lines
VB
Do While sr.Peek() >= 0
    line = sr.ReadLine() 
Loop 

but i am getting an error on first line which says: method arguments must be enclosed in parentheses
Posted
Updated 15-May-13 20:37pm
v3

Try this
C#
string fileText = string.Empty;
                using (StreamReader sr = new StreamReader("YoufilePathHere"))
                {
                    fileText = sr.ReadToEnd();      //it will read all text of file.
                }



in VB

VB
Dim fileText As String = String.Empty
Using sr As New StreamReader("YoufilePathHere")
		'it will read all text of file.
	fileText = sr.ReadToEnd()
End Using
 
Share this answer
 
v2
The problem is not in the code fragment you show: That is perfectly valid and will compile without problems.

Look at the code immediately before this, It is likely that you have forgotten something, or left a spurious underline somewhere. Try double clicking on the actual error message - it may take you to the line with the real problem.

If not, we would need a larger code fragment to help!
 
Share this answer
 
Comments
shashank 1068 16-May-13 2:47am    
i am getting an error on >=0
OriginalGriff 16-May-13 3:13am    
If I copy and paste your code into my app:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click, Button2.Click
Dim sr As StreamReader
Dim line As String
Do While sr.Peek() >= 0
line = sr.ReadLine()
Loop
End Sub
It compiles ok - it complains that "sr" is not initialized, but that's all.
The problem is not in that code - it's earlier in your method and that's affecting the line you see.
What's the rest of the method look like?
shashank 1068 16-May-13 2:48am    
it alo says expression expected
I am new to programming , but I think the following line is creating problem.

sr.Peek() >= 0

as compiler is considering >=0 as argument of "sr.Peek()"

so get the result of function in some variable or like something, and dn put comparison operator on that.


Regards.

:)
 
Share this answer
 
First of all, have a look here: Method arguments must be enclosed in parentheses[^]

Try to change line which occurs error to:
VB
Do While (sr.Peek() > -1)


Why do i made some changes in your code?
Quote:
An integer representing the next character to be read, or -1 if there are no characters to be read or if the stream does not support seeking.


More: StreamReader.Peek (VB.NET)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900