Author Topic: VB.NET to C#  (Read 8672 times)

0 Members and 1 Guest are viewing this topic.

pkohut

  • Bull Frog
  • Posts: 483
Re: VB.NET to C#
« Reply #15 on: December 27, 2010, 03:01:22 AM »
in that case, how about
Code: [Select]
if(Convert.ToBoolean(e.Context.History & PointHistoryBits.NotDigitizer))

Hm, heard something about boats and floating...
New tread (not retired) - public repo at https://github.com/pkohut

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: VB.NET to C#
« Reply #16 on: December 27, 2010, 03:05:43 AM »
in that case, how about
Code: [Select]
if(Convert.ToBoolean(e.Context.History & PointHistoryBits.NotDigitizer))

Hm, heard something about boats and floating...


eh :roll:?    just throwing out alternatives

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: VB.NET to C#
« Reply #17 on: December 27, 2010, 03:08:05 AM »
in that case, how about

Code: [Select]
if(Convert.ToBoolean(e.Context.History & PointHistoryBits.NotDigitizer))

This seems to be closer to the VB syntax. It seems to me, VB can have non explcit casts.
Speaking English as a French Frog

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: VB.NET to C#
« Reply #18 on: December 27, 2010, 03:14:46 AM »
It's just C# is a bit more "type safe" than other languages, I wonder what refector shows in this case...

pkohut

  • Bull Frog
  • Posts: 483
Re: VB.NET to C#
« Reply #19 on: December 27, 2010, 03:14:55 AM »
eh :roll:?    just throwing out alternatives

Understood. The humor must of stopped at keyboard  ;-)
New tread (not retired) - public repo at https://github.com/pkohut

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: VB.NET to C#
« Reply #20 on: December 27, 2010, 03:21:03 AM »
Yeah, I better go get myself a few happy pills BRB  :-)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: VB.NET to C#
« Reply #21 on: December 27, 2010, 03:26:27 AM »
Ok chugged a redbull... where was I   :laugh:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: VB.NET to C#
« Reply #22 on: December 27, 2010, 04:28:26 AM »
That should teach me about not testing before posting.  :oops:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

sinc

  • Guest
Re: VB.NET to C#
« Reply #23 on: December 27, 2010, 01:05:02 PM »

Now as per the suggestions given yesterday, if I use

 if(args.Context.History & PointHistoryBits.NotDigitizer == 2)

compiler says that we cannot compare int with PointHistoryBits.NotDigitizer, so even this version is not working.


That's because of operator precedence.  You would need to do something like the following:

Code: [Select]
if ((args.Context.History & PointHistoryBits.NotDigitizer) == 2)
Without explicit parentheses, it gets parsed as:

Code: [Select]
if (args.Context.History & (PointHistoryBits.NotDigitizer == 2))

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: VB.NET to C#
« Reply #24 on: December 27, 2010, 05:04:47 PM »
After some tests:

((args.Context.History & PointHistoryBits.NotDigitizer) == 2) => does not work

((e.Context.History & PointHistoryBits.NotDigitizer) > 0) => does not work

((e.Context.History & PointHistoryBits.NotDigitizer) != 0)) => works

(((int)e.Context.History & (int)PointHistoryBits.NotDigitizer) == 2) => works

(((int)e.Context.History & 2) == 2) => works

((e.Context.History & PointHistoryBits.NotDigitizer) == PointHistoryBits.NotDigitizer) => works

((e.Context.History & PointHistoryBits.NotDigitizer) > PointHistoryBits.DidNotPick) => works

(Convert.ToBoolean(e.Context.History & PointHistoryBits.NotDigitizer)) => works
Speaking English as a French Frog

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: VB.NET to C#
« Reply #25 on: December 27, 2010, 11:24:07 PM »
Just to confuse the iisue more,
The VB code as written is massaged behind the scenes and the decision logic is changed ... one of the reasons ( no, we won't go there today :) )

This is the VB code
Code: [Select]
   ' ok, so now lets do something really pointless! space invaders!
    If (e.Context.History And PointHistoryBits.NotDigitizer) Then
      ' this means the mouse has been clicked... so...
      ' create a Circle
      Dim circle As Circle = New Circle(e.Context.RawPoint, Vector3d.ZAxis, 10)
      ' draw it
      e.Context.DrawContext.Geometry.Draw(circle)
      ' wait for a while
      System.Threading.Thread.Sleep(50)
      ' draw it
      circle.Radius = 20
      e.Context.DrawContext.Geometry.Draw(circle)
      ' wait for a while
      System.Threading.Thread.Sleep(50)
      ' draw it
      circle.Radius = 40
      e.Context.DrawContext.Geometry.Draw(circle)
      ' wait for a while
      System.Threading.Thread.Sleep(50)
      ' draw it
      circle.Radius = 80
      e.Context.DrawContext.Geometry.Draw(circle)
      ' wait for a while
      System.Threading.Thread.Sleep(50)

    End If

These are snaphots into the compiled code in Reflector // both the VB and C# representation of the Intermediate Langusge in the compiled DLL
note : the piccys will only be visible to members logged-in.
« Last Edit: December 27, 2010, 11:28:21 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

jgr

  • Guest
Re: VB.NET to C#
« Reply #26 on: December 28, 2010, 08:11:48 AM »
This code is not correct because it only works if Option Strict = off. (this is a compiler option)
Code: [Select]
If (e.Context.History And PointHistoryBits.NotDigitizer) Then
This is the right way.
Code: [Select]
If (e.Context.History And PointHistoryBits.NotDigitizer) = PointHistoryBits.NotDigitizer Then

This also works
Code: [Select]
If (CInt(e.Context.History) And Cint(PointHistoryBits.NotDigitizer)) = 64 Then

If (CInt(e.Context.History) And 64) = 64 Then

If CBool(e.Context.History And PointHistoryBits.NotDigitizer) Then

...



Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: VB.NET to C#
« Reply #27 on: December 28, 2010, 08:20:40 AM »
This code is not correct because it only works if Option Strict = off. (this is a compiler option)
< .. >

That statement is debatable.
Option Strict = off is an available Option .. so the code is correct in the form it's used.

The real discussion should be "why is Option Strict available as an Option, and should it be used at all"
.. but I won't participate 'cause I'm prejudiced  :-P

.. just my opinion :)

 


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

jgr

  • Guest
Re: VB.NET to C#
« Reply #28 on: December 28, 2010, 08:55:28 AM »
Option Strict = off is an available Option .. so the code is correct in the form it's used.

The real discussion should be "why is Option Strict available as an Option, and should it be used at all"

It is an inheritance from vb6. This option does not exist in vb6 but internally is always off.

Option Strict On provides strong typing.
http://msdn.microsoft.com/en-us/library/zcd4xwzs%28v=VS.100%29.aspx