Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. "Clever" classic VB trick

"Clever" classic VB trick

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpdebugginghelpquestion
4 Posts 4 Posters 36 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paul Reynolds
    wrote on last edited by
    #1

    I used to include this function in some classic VB apps: Function RunningInDevEnv() as Boolean On Error Resume Next Debug.Print 1/0 RunningInDevEnv = (Err.Number <> 0) End Function I was curious and tried running this in VB.NET: Function RunningInDevEnv() As Boolean On Error Resume Next Debug.Print(1 / 0) Return (Err.Number <> 0) End Function It compiles in VB.NET but always returns True. I noticed the C# compiler does not accept 1 / 0 at all. Is the VB.NET compiler being so forgiving here a good thing? Sad to say some poor soul as I write this is probably trying to port one of my old VB apps to VB.NET and wondering why some "weird" behavior by the classic app in development mode is not carrying over to VB.NET. I hope the gods above will forgive me. I think the lesson is to try to avoid clever tricks like this, even when they work (for awhile).

    M I 2 Replies Last reply
    0
    • P Paul Reynolds

      I used to include this function in some classic VB apps: Function RunningInDevEnv() as Boolean On Error Resume Next Debug.Print 1/0 RunningInDevEnv = (Err.Number <> 0) End Function I was curious and tried running this in VB.NET: Function RunningInDevEnv() As Boolean On Error Resume Next Debug.Print(1 / 0) Return (Err.Number <> 0) End Function It compiles in VB.NET but always returns True. I noticed the C# compiler does not accept 1 / 0 at all. Is the VB.NET compiler being so forgiving here a good thing? Sad to say some poor soul as I write this is probably trying to port one of my old VB apps to VB.NET and wondering why some "weird" behavior by the classic app in development mode is not carrying over to VB.NET. I hope the gods above will forgive me. I think the lesson is to try to avoid clever tricks like this, even when they work (for awhile).

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      Follow the white rabbit... VB6 wouldn't compile Debug.Print statements into the final code, and therefore wouldn't compile in the expression being evaluated either. Therefore if you were in the environment the division by zero would cause an error to be raised but you'd resume at the next statement, and the error number would be set to something other than 0, but in the compiled code the line causing the error wouldn't be present, so the problem wouldn't occur. A debug build of the VB.NET code would cause the error to occur and the operation would return True. A release build should not. See the documentation for ConditionalAttribute. The C# compiler tends to have better diagnostics and won't allow you to compile division by a literal zero. You'd have to use a variable containing the value 0.

      Stability. What an interesting concept. -- Chris Maunder

      1 Reply Last reply
      0
      • P Paul Reynolds

        I used to include this function in some classic VB apps: Function RunningInDevEnv() as Boolean On Error Resume Next Debug.Print 1/0 RunningInDevEnv = (Err.Number <> 0) End Function I was curious and tried running this in VB.NET: Function RunningInDevEnv() As Boolean On Error Resume Next Debug.Print(1 / 0) Return (Err.Number <> 0) End Function It compiles in VB.NET but always returns True. I noticed the C# compiler does not accept 1 / 0 at all. Is the VB.NET compiler being so forgiving here a good thing? Sad to say some poor soul as I write this is probably trying to port one of my old VB apps to VB.NET and wondering why some "weird" behavior by the classic app in development mode is not carrying over to VB.NET. I hope the gods above will forgive me. I think the lesson is to try to avoid clever tricks like this, even when they work (for awhile).

        I Offline
        I Offline
        Ian MacLean
        wrote on last edited by
        #3

        .net already has the method. system.diagnostics.debugger.isattached

        A 1 Reply Last reply
        0
        • I Ian MacLean

          .net already has the method. system.diagnostics.debugger.isattached

          A Offline
          A Offline
          Anton Afanasyev
          wrote on last edited by
          #4

          try creating a usercontrol, and put that control on a form. that method isnt very reliable as you will see.


          :badger:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups