473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Cannot convert to bool error in VB but not C#

In C# this line compiles and works fine:
if (Request.Params["something"] != null)

But when trying to convert this to VB.NET and changing it to:
if (Request.Params["something"] <> Nothing)
I get the following error: Compiler Error Message: BC30311: Value of type
'System.Collections.Specialized.NameValueCollectio n' cannot be converted to
'Boolean'

Anyone know why this works in C# but not VB? How do I fix this?

Basically I do not care what the value of the param is, I just want to know
whether its set to anything or not. If I try and check its value without
testing it for null, then I will receive an error from trying to access a
null object. So it seems I need a way to check for null in the first place,
but cannot figure out how to do this in VB.NET. Any ideas? Thank you.


Nov 20 '05 #1
12 2768
* "Bill Dee" <sp**@spamabc.com> scripsit:
In C# this line compiles and works fine:
if (Request.Params["something"] != null)

But when trying to convert this to VB.NET and changing it to:
if (Request.Params["something"] <> Nothing)
That's not VB.NET code!!!

\\\
If Request.Params("something") Is Nothing Then
...
End If
///
I get the following error: Compiler Error Message: BC30311: Value of type
'System.Collections.Specialized.NameValueCollectio n' cannot be converted to
'Boolean'

Anyone know why this works in C# but not VB? How do I fix this?


Fix your code to make it compile in VB.NET.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Hi Bill,

Probably

if Not (Request.Params("something") Is Nothing then

Cor
Nov 20 '05 #3
"Bill Dee" <sp**@spamabc.com> schrieb
In C# this line compiles and works fine:
if (Request.Params["something"] != null)

But when trying to convert this to VB.NET and changing it to:
if (Request.Params["something"] <> Nothing)
I get the following error: Compiler Error Message: BC30311: Value of
type 'System.Collections.Specialized.NameValueCollectio n' cannot be
converted to 'Boolean'

Anyone know why this works in C# but not VB? How do I fix this?

Use the correct operator to compare references: Is

if bla is nothing then

or

if not bla is nothing then
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
> > But when trying to convert this to VB.NET and changing it to:
if (Request.Params["something"] <> Nothing)


That's not VB.NET code!!!

\\\
If Request.Params("something") Is Nothing Then
...
End If
///

That is not good !!!!

:-))))

Cor
Nov 20 '05 #5
Errata:
In C# this line compiles and works fine:
if (Request.Params["something"] != null)

But when trying to convert this to VB.NET and changing it to:
if (Request.Params["something"] <> Nothing)


That's not VB.NET code!!!

\\\
If Request.Params("something") Is Nothing Then


.... sorry, should read: 'If Not ... Is Nothing'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Probably

if Not (Request.Params("something") Is Nothing then


.... won't compile!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7
On Tue, 4 May 2004 20:08:30 +0200, Armin Zingler wrote:

Use the correct operator to compare references: Is

if bla is nothing then

or

if not bla is nothing then


And soon to be availble in Whidbey: IsNot

if bla IsNot Nothing Then

or

'This one is strange!!
If Not bla IsNot Nothing Then

--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 20 '05 #8
"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net">
schrieb
On Tue, 4 May 2004 20:08:30 +0200, Armin Zingler wrote:

Use the correct operator to compare references: Is

if bla is nothing then

or

if not bla is nothing then


And soon to be availble in Whidbey: IsNot

if bla IsNot Nothing Then


Looking forward to. :)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9
> > if Not (Request.Params("something") Is Nothing then

... won't compile!


if Not Request.Params("something") Is Nothing then

You are right I was looking at it, and thought there is something wrong but
what.
I should have put it in the IDE however I did not.

Thanks

Cor
Nov 20 '05 #10
Hi Chris,
'This one is strange!!
If Not bla IsNot Nothing Then


I find "object Is Something", much nicer

However what would be the equivalent in C#

Just my thoughts about it.

Cor
Nov 20 '05 #11

"Cor Ligthert" <no**********@planet.nl> wrote
'This one is strange!!
If Not bla IsNot Nothing Then


I find "object Is Something", much nicer


Wouldn't that be the same as:

If bla Is Nothing Then
LFS

Nov 20 '05 #12
Hey, Larry, are you making the move to VB.Net or just checking it out? Somehow, I didn't expect to see you here.

--
Al Reid

"It ain't what you don't know that gets you into trouble. It's what you know
for sure that just ain't so." --- Mark Twain

"Larry Serflaten" <se*******@usinternet.com> wrote in message news:Oc**************@TK2MSFTNGP11.phx.gbl...

"Cor Ligthert" <no**********@planet.nl> wrote
'This one is strange!!
If Not bla IsNot Nothing Then


I find "object Is Something", much nicer


Wouldn't that be the same as:

If bla Is Nothing Then
LFS

Nov 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Chris | last post by:
Hi, I try to print out truth-tables for an &&-operation using the following code, unfortunatly I get compiler errors : for ( byte i1=0; i1<=1; i1++) { for ( byte i2=0; i2<=1; i2++) { bool...
2
by: Jeff | last post by:
I get the following error: Cannot implicitly convert type 'Factory.Stack.pArrayStack' to 'Factory.Stack.StackDefs.ImStack' at compile time. I thought perhaps there was a mismatch between the...
2
by: Patrick Olurotimi Ige | last post by:
When i convert:- this code from VB to C# Why do i get error "Cannot implicitly convert type 'object' to 'bool' VB --- If cmdcommand.Parameters("ReturnValue").Value = 1 Then lblStatus.Text =...
5
by: Andrew Robinson | last post by:
Any easy answer what is wrong here? private List<string> BodyWords = new List<string>(); string word = "Andrew"; the following causes a compilation error:
6
by: Doug | last post by:
Hi I have a short piece of trial code that compares some input and then produces a message based on the value. However I get a build error that i dont know how to resolve ' Cannot implicitly...
2
by: Christophe | last post by:
class A {} class B {} interface MyInterface { void method(A a); void method(B b); }
2
by: Nick | last post by:
I am trying to find out if particular array element contains InputOutput value. private static int FillParameters(DbCommand command, SqlParameter p) { int x = 0; //int initalize to hold zero...
6
by: John | last post by:
The following code: int test = 1; bool isTrue = (bool)test; results in a compiler error: Cannot convert type 'int' to 'bool' wtf, any ideas on how to work around this?
3
by: efdeugenio | last post by:
Hi, I will really appreciate if someone cans help me with this: I have a managed c++ class that I am calling from C#. The declaration of a function in this class is: bool CanAddTemplate(unsigned...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.