Showing posts with label wrong. Show all posts
Showing posts with label wrong. Show all posts

Wednesday, March 28, 2012

String.Equals Wrong Parameter ?

In VisStudio.Net 1,0, I am receiving the error "Parameter is Incorrect" on lines 5, 6, and 7 below. Line 8 works correctly. This is code I picked up from the MSFT website - any ideas as to what could be wrong with it?

Thanks
Mike Thomas

1 Dim sb As New StringBuilder("abcd")
2 Dim str1 As [String] = "abcd"
3 Dim str2 As [String] = Nothing
4 Dim o2 As [Object] = Nothing

5 ? str1.Equals(sb)
6 ? str1.Equals(o2)
7 ? str1.Equals(str2)
8 ? [String].Equals(str1, str2)

At top is

Imports System.String
Imports System.TextHi,

my guess would be that you have Option Strict set to On so that you have to cast specifically. Try something like this:


str1.Equals(sb.ToString)

Grz, Kris.
Many thanks Kris - that was exactly it.

Mike Thomas

Tuesday, March 13, 2012

stuck in a loop

Hi

I try to use this piece of code, but the page seems to get stuck in the loop. What am I doing wrong here?

Function NumberOfLinesInFile()
Dim path As String = Server.MapPath("row.txt")
Dim sr As StreamReader = New StreamReader(path)
Dim i As Integer
i = 0
Do While sr.Peek() >= 0
i = i + 1
Loop
sr.Close()
Return i
End Function

Regards

Mhello, what if sr.Peek() is always >= 0 ? check the values returned by sr !!!
The Peek function does not move to the next character, it only consumes it. Try using the sr.Read() instead.

hope this helps,

sivilian