473,387 Members | 1,585 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,387 software developers and data experts.

Convert VB to C#, Operator "Not"

ano
Hi all,

I try to convert VB codes to C#. I got this error "Operator '!'cannot be
applied to operand of type 'long'".

Any ideas? Why doesn't "Not SYNCHRONIZE" equivalent to "!SYNCHRONIZE"?

Thanks,

VB:

Public Const SYNCHRONIZE = &H100000
Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or
KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))

C#:
public const long SYNCHRONIZE = 0x100000;
public const bool KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL
| KEY_QUERY_VALUE
| KEY_SET_VALUE
| KEY_CREATE_SUB_KEY
| KEY_ENUMERATE_SUB_KEYS
| KEY_NOTIFY
| KEY_CREATE_LINK)
& !SYNCHRONIZE);
Jun 26 '06 #1
5 3122
> Why doesn't... <snip>
Because it means something different?

! is the boolean negation operator
~ is the bitwise complement operator

Try ~SYNCHRONIZE instead

Marc
Jun 26 '06 #2
ano
I have tried ~SYNCHRONIZE but I got this error "Cannot implicitly convert
type 'long' to 'bool'".
"Marc Gravell" wrote:
Why doesn't... <snip>

Because it means something different?

! is the boolean negation operator
~ is the bitwise complement operator

Try ~SYNCHRONIZE instead

Marc

Jun 26 '06 #3
That is the final assignment step; depending on what your code is trying to
do (I must admit, I'm not 100% sure from the sample alone) then you probably
need to add " != 0" or " == {the bytes you are looking for}" - the latter
may require shoving the value into a variable first.

Basically, it comes down to integer / long values deliberately not being
"true" or "false"; if VB long 0 means "false", then you probably just need
to add the != 0 explicitely.

Marc
Jun 26 '06 #4
ano wrote:
I have tried ~SYNCHRONIZE but I got this error "Cannot implicitly convert
type 'long' to 'bool'".


Constant KEY_ALL_ACCESS is not boolean, it is obviously a long int,
since SYNCHRONIZE is declared long. Also, when you use bitwise operators
between values, the result is not a boolean, it's an int (or long, or
uint, or something).

HTH, Tom.
Jun 26 '06 #5
ano
Thanks, I have made a mistake.
Now I changed "bool" to "int".

Thanks a lot,
ano

"Marc Gravell" wrote:
That is the final assignment step; depending on what your code is trying to
do (I must admit, I'm not 100% sure from the sample alone) then you probably
need to add " != 0" or " == {the bytes you are looking for}" - the latter
may require shoving the value into a variable first.

Basically, it comes down to integer / long values deliberately not being
"true" or "false"; if VB long 0 means "false", then you probably just need
to add the != 0 explicitely.

Marc

Jun 26 '06 #6

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

Similar topics

0
by: Doug | last post by:
Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Lines: 14 Message-ID: <9DxFc.23833$bs4.23734@newsread3.news.atl.earthlink.net> Date: Sat, 03 Jul 2004...
0
by: Pedro Hernandez | last post by:
Hello! I have some (many) text files produced on windows system that I need to process a bit, so I wrote a perl script to do the job. The files contains characters used in Spanish (e.g. ó, é,...
1
by: Andrew Hoi | last post by:
Hi, I have a web site that use META tag like below : <META content=blendTrans(Duration=1.0) http-equiv=Page-Enter> <META content=blendTrans(Duration=1.0) http-equiv=Page-Exit> it work...
9
by: aden | last post by:
I have read the years-old threads on this topic, but I wanted to confirm what they suggest. . . Can the this pointer EVER point to a type different from the class that contains the member...
13
by: gary | last post by:
Hi, We all know the below codes are dangerous: { int *p = new int; delete p; delete p; } And we also know the compilers do not delete p if p==NULL. So why compilers do not "p = NULL"...
5
by: VB Programmer | last post by:
I want to set the enabled property of a text box based on if a checkbox is checked or not. This works.... txtPort.Enabled = ckDefaultPort.Checked; But, I want the enabled property to be the...
6
by: =?Utf-8?B?UmljaA==?= | last post by:
If Not st1.Equals("something") then Do Something Else End If if str1 != "something" Then ... I realize that != is C# stuff and/or can be also be used in Tsql, but is there any implementation...
6
by: grbgooglefan | last post by:
I am creating functions, the return result of which I am using to make decisions in combined expressions. In some expressions, I would like to inverse the return result of function. E.g....
2
by: K Viltersten | last post by:
The following works fine doing exactly what is supposed. <asp:LinkButton id="id" runat="server" Text="Text"> </asp:LinkButton> If i change it to the following, the callback method doesn't do...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.