473,836 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cast Integer as Boolean?

Hello All,

How can I cast a System.Int32 as a boolean in VB.NET?

I know I used to used Cbool(myInt) in VB6, but I cxan't seem to find the
.NET equivalent.

-Joel
Nov 21 '05
12 23293
Joel,
As Cor & Armin suggests,

| How can I cast a System.Int32 as a boolean in VB.NET?
CBool is a valid .NET VB.NET keyword.

Convert.ToBoole an will always result in a call to another routine (that the
JIT may or may not inline).

CBool(Int32) is an IL statement.

For details of using CBool verses calling Convert.ToBoole an see:

http://www.panopticoncentral.net/arc...6/07/1200.aspx

www.panopticoncentral.net is Paul Vick's blog, Paul Vick is the Technical
Lead of the Visual Basic.NET Development team at Microsoft.

Hope this helps
Jay

"Joel Whitehouse" <jo************ @gmail.com> wrote in message
news:O%******** ********@TK2MSF TNGP12.phx.gbl. ..
| Hello All,
|
| How can I cast a System.Int32 as a boolean in VB.NET?
|
| I know I used to used Cbool(myInt) in VB6, but I cxan't seem to find the
| .NET equivalent.
|
| -Joel
Nov 21 '05 #11
Thanks Armin ,,,
for the clear explanation


"Armin Zingler" <az*******@free net.de> wrote in message
news:uo******** ******@TK2MSFTN GP12.phx.gbl...
"Armin Zingler" <az*******@free net.de> schrieb
:-) ). In this case it is done for System.Convert. ToInt32:


....done for System.Convert. ToBoolean

Armin

Nov 21 '05 #12
No i had not yet read this page ,,, now i did ... thank you for pointing me
at it ,, it had some verry interesting info

now i know for sure that

IsFalse = CBool(test)
and
IsFalse = CType(test, Boolean)

produce the same IL code

if you meant with "most optimized" the shortest way of coding the fastest
method you are right ,,, but i might have misunderstood that for "the one
and only fastest method in code execution " this is were my doubts were

regards ( groeten )

Michel Posseth


"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
Michel,

Do you know this page?

http://msdn.microsoft.com/library/de...tinternals.asp

And than about this in the section
Conversion Functions, CType, DirectCast, and System.Convert

Cor

Nov 21 '05 #13

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

Similar topics

4
10479
by: Ray | last post by:
When a single-bit bitfield that was formed from an enum is promoted/cast into an integer, does ANSI C say anything about whether that integer should be signed or unsigned? SGI IRIX cc thinks it is an unsigned integer, so I see a +1 if the bit is set. Microsoft VC++ thinks it's signed, so I see -1 if the bit is set. Ex. typedef enum {
3
2296
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New DataSet ' Create connection Dim cn As New OleDbConnection With cn .connectionstring =
3
10522
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my columns is a template column where I'd like to evaluate the data brought back from the db and populate the column with a "Y" or "N" depending on the value in the db. Here is the code that is causing it as well as the error (below). ERROR...
1
4919
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm specifiying my code: The Code used in Visual Studio: Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As String, ByVal iDate As Date) As String 'Dim Ret As Integer
4
3843
by: Mike Cooper | last post by:
There is something about inherited classes I evidently don't know... I wrote the following class: Class Class1 inherits System.Windows.Forms.DataGridTextBoxColumn End Class There is absolutely no added functionality to it.
9
7137
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but when I tried the program on the Win98 system it will be running on, I get the following error: Cast from string "2076719" to type 'Long' is not valid I am not sure why I only get this error on the Win98 system or how to go about correcting...
21
1927
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New DataSet ' Create connection Dim cn As New OleDbConnection With cn .connectionstring = "provider=Microsoft.Jet.OLEDB.4.0;" & _
6
2320
by: John-Arne Lillebø | last post by:
Hi. I run into this problem and i could need some help to solve it. The project is an ASP.NET Web project. Including code sample of the problem. Any idea what is causing the error message ? John-Arne Lillebø
18
3128
by: mark | last post by:
class SORef {...}; class SelectedFORef : public SORef {...}; SOFORef SOCastToSOF(SORef sor) { SelectedFORef sof=nil; sof=dynamic_cast<SelectedFORef>(sor); return sof; };
0
9657
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10822
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7774
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6975
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4443
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3103
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.