PC Review


Reply
Thread Tools Rate Thread

Convert VB to C#, Operator "Not"

 
 
=?Utf-8?B?YW5v?=
Guest
Posts: n/a
 
      26th Jun 2006
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);
 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      26th Jun 2006
> Why doesn't... <snip>
Because it means something different?

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

Try ~SYNCHRONIZE instead

Marc


 
Reply With Quote
 
=?Utf-8?B?YW5v?=
Guest
Posts: n/a
 
      26th Jun 2006
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
>
>
>

 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      26th Jun 2006
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


 
Reply With Quote
 
Tomislav Tustonic
Guest
Posts: n/a
 
      26th Jun 2006
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.
 
Reply With Quote
 
=?Utf-8?B?YW5v?=
Guest
Posts: n/a
 
      26th Jun 2006
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
>
>
>

 
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
Configure Win2K "Search" Boolean "AND" operator Clueless in Seattle Microsoft Windows 2000 1 19th Apr 2008 02:39 PM
Convert VB to C#, Operator "Or" =?Utf-8?B?YW5v?= Microsoft C# .NET 5 22nd Jun 2006 04:41 PM
Text "comparison" operator for "contains" used in an "IF" Function =?Utf-8?B?UGF3YXNv?= Microsoft Excel Worksheet Functions 3 19th Jan 2006 06:42 PM
LOTUS TRANSITION KEYS "/" "R" / "V" convert formulas to text. =?Utf-8?B?Ym9iQGdvcmRvbmVuZ2luZWVyaW5nLmNvbQ==?= Microsoft Access Getting Started 3 18th Jan 2006 09:15 AM
Outlook 2003: No "AND" "OR" operator in message rules Richard Microsoft Outlook 0 9th Jan 2004 08:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:23 AM.