invalid cast exception

  • Thread starter Thread starter cs_hart
  • Start date Start date
C

cs_hart

I am getting an invalid cast exception - cast from string to type
double is not valid.

Dim curName As String
Dim prevName As String = ""
curName = CStr(rows.Item(i).Item(colSchName)) ' extract name from
database row
If (curName.CompareTo(prevName <> 0)) Then <--- exception occurs on
this line

I do a cast on line 3 but that is not the one getting an exception. Any
help appreciated...charlie
 
CS,

Any reason that you do not just

\\\
If curName <> "" then
///

You make me curious

Cor
 
THis is the first time through. If these are not equal then I save it
in a list , assing curname to prevname and go to the next. I'm trying
to eliminate any duplicates during the processing
 
CS,

What is than the difference with this sentence in my idea it is in this case
exactly the same

If (curName.CompareTo(prevName)) <> 0 Then

(With corrected error, in your code are you testing agains an evaluation)

It is good to set Option Strict On in your program, this will than be showed
direct when you are making your code.

Cor
 
You've got your not equal to zero check in the wrong place.

The line should read:

If (curName.CompareTo(prevName) <> 0) Then

That should fix your cast exception error.

Hope this helps,
Brian Swanson
 
Hi CS,

the closing braket is at the wrong place, so you compare prevName to 0

If (curName.CompareTo(prevName) <> 0)
^

Roland
 
Back
Top