PC Review


Reply
Thread Tools Rate Thread

invalid cast exception

 
 
cs_hart@yahoo.com
Guest
Posts: n/a
 
      25th Feb 2005
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

 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      25th Feb 2005
CS,

Any reason that you do not just

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

You make me curious

Cor


 
Reply With Quote
 
 
 
 
cs_hart@yahoo.com
Guest
Posts: n/a
 
      25th Feb 2005
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

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      25th Feb 2005
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


 
Reply With Quote
 
Brian Swanson
Guest
Posts: n/a
 
      25th Feb 2005
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

"(E-Mail Removed)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed):
> 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


 
Reply With Quote
 
=?Utf-8?B?Um9sYW5kIFBvbHplcg==?=
Guest
Posts: n/a
 
      25th Feb 2005
Hi CS,

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

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

Roland



"(E-Mail Removed)" wrote:

> 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
>
>

 
Reply With Quote
 
cs_hart@yahoo.com
Guest
Posts: n/a
 
      25th Feb 2005
Thanks - obviously I didn't see that.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Looping through Outlook Contacts gives me a 'Invalid Cast Exception' Chris Thunell Microsoft Outlook 5 21st Apr 2005 01:40 PM
Invalid cast exception when assign combobox returned value to the variable Microsoft ADO .NET 1 15th Jan 2005 05:30 PM
Invalid Cast Exception Calling Bsse Class Method Nick Flandry Microsoft ASP .NET 4 12th Feb 2004 05:32 PM
Invalid Cast Exception on Context.ApplicationInstance Mark Olbert Microsoft ASP .NET 2 5th Dec 2003 03:43 AM
Question: Invalid Cast Exception Error VB Programmer Microsoft ASP .NET 4 28th Oct 2003 04:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:30 AM.