Conditional messages

Gloops 41 Reputation points
2021-01-10T06:20:29.433+00:00

Hello everybody,

Oh, Windows Forms you mean ...
I do not know how I found it, but this is what I was looking for.

To help debug a program, I tried and used conditional programming, to display messages only during the debugging phase.

They seem like this :

#if TODEBUG
            MessageBox.Show("Debugging was here");
#endif

This is supposed to be displayed only when the program includes this during compilation :

#DEFINE TODEBUG

Well, on the development machine, on Windows 10, this executes quite as wished.
But on the target machine, on Vista, the execution pays no attention to the #DEFINE TODEBUG. As I remember the messages are always diplayed.

Does anybody understand that ?

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,901 questions
0 comments No comments
{count} votes

Accepted answer
  1. WayneAKing 4,921 Reputation points
    2021-01-10T14:35:43.73+00:00

    I compiled the program on the development machine,
    and then I launched it :
    on the development machine
    on the target machine.

    Preprocessor directives such as #define are in effect
    at compile time only. They are no longer visible or
    active at run time, as their effect has already been
    applied when the program was built.

    So if you are seeing a difference at run time - when
    an exe you built is executed - then that difference
    cannot be caused by a preprocessor directive itself.

    Perhaps you are not actually executing the same exe
    on both machines.

    I made a copy/paste of the executable between both machines.

    What exactly do you mean by "copy/paste"?

    How actually did you copy the exe from the development
    machine to the target machine? Describe the steps precisely.

    • Wayne
    1 person found this answer helpful.
    0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Viorel 118K Reputation points
    2021-01-10T08:53:07.487+00:00

    Probably TODEBUG was defined in Project Properties (Build tab, “Conditional compilation symbols”) or it was a #define TODEBUG statement when the program was compiled.

    0 comments No comments

  2. Gloops 41 Reputation points
    2021-01-10T11:06:08.693+00:00

    Well, I try and explain better;

    I compiled the program on the development machine, and then I launched it :

    • on the development machine
    • on the target machine.

    I made a copy/paste of the executable between both machines.

    0 comments No comments

  3. Gloops 41 Reputation points
    2021-01-10T11:51:16.653+00:00

    Initially I tested with #DEFINE TODEBUG at the top of the program, as I said.

    I just tested with the properties, Build tab.

    On the development machine, it works jolly good in both cases.

    I shall test again on the target machine in a few hours.

    0 comments No comments

  4. Karen Payne MVP 35,436 Reputation points
    2021-01-10T14:28:00.863+00:00

    You can also use

    If Debugger.IsAttached Then
        MessageBox.Show("Debugging was here")
    End If
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.