Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a lot of debug.print lines for testing.
But some seem to be passive / do not fire.

. . .
. . .
                //if (bTeamOpponent == true | MyForm.iCoSpieler != -1)
                if (bTeamOpponent == true)
                {
                    if (Conversions.ToBoolean(Operators.ConditionalCompareObjectGreater(cpc.Count, 0, false)))
                    {
                        for (int n = 0, loopTo2 = Conversions.ToInteger(Operators.SubtractObject(cpc.Count, 1)); n <= loopTo2; n++)
                        {
                            PlayingCard pc = (PlayingCard)CardsPanel.Children[n];
                            if (Conversions.ToBoolean(Operators.ConditionalCompareObjectEqual(pc.CardType, LeadSuitID, false)))
                            {
                                // If .Item(n).CardType <> TrumpCardID Then
                                var sO = default(string);
                                if (TrumpCardID == 4)
                                    sO = "X";
                                if (TrumpCardID != 4)
                                    sO = "O";
                                if (Conversions.ToBoolean(Operators.ConditionalCompareObjectEqual(pc.CardShortName.Contains(sO), false, false)) && Conversions.ToBoolean(Operators.ConditionalCompareObjectEqual(pc.CardShortName.Contains("U"), false, false)))
                                {
                                    if (String.Equals(MyForm.sRufAs, pc.CardShortName + " " + pc.CardSymbol))
                                    {
                                        CurrentCard = pc;
                                        return CurrentCard;
                                        Debug.Print("ACP 488 CurrentCard: '" + CurrentCard.CardShortName + " " + CurrentCard.CardSymbol);
                                    }
                                    else
                                    {
                                    CurrentCard = pc;
                                    }
                                }
                                // End If
                            }
                        }
                    }
                    // Friend is unknown (or Solo?)

                    if (Conversions.ToBoolean(Operators.ConditionalCompareObjectGreater(cpc.Count, 0, false)) && MyForm.RufAs.IsAlreadyPlayed == false && MyForm.iCoSpieler > -1)
                    {
                            for (int n = 0, loopTo3 = Conversions.ToInteger(Operators.SubtractObject(cpc.Count, 1)); n <= loopTo3; n++)
                        {
                            PlayingCard pc = (PlayingCard)CardsPanel.Children[n];
                            if (Conversions.ToBoolean(Operators.ConditionalCompareObjectNotEqual(pc.CardType, TrumpCardID, false)) && Conversions.ToBoolean(Operators.ConditionalCompareObjectEqual(pc.CardType, MyForm.RufAs.CardType, false)))
                            {
                                var sO = default(string);
                                if (TrumpCardID == 4)
                                    sO = "X";
                                if (TrumpCardID != 4)
                                    sO = "O";
                                if (Conversions.ToBoolean(Operators.ConditionalCompareObjectEqual(pc.CardShortName.Contains(sO), false, false)) && Conversions.ToBoolean(Operators.ConditionalCompareObjectEqual(pc.CardShortName.Contains("U"), false, false)))
                                {
                                    CurrentCard = pc;
                                    MyForm.RufAs.IsAlreadyPlayed = true;
                                    Debug.Print("ACP 511 CurrentCard: '" + CurrentCard.CardShortName + " " + CurrentCard.CardSymbol);
                                }
                            }
                        }
                    }
                }
                // CurrentCard Is Nothing 
                if (Conversions.ToBoolean(Operators.ConditionalCompareObjectGreater(cpc.Count, 0, false)) && CurrentCard is null)
                {
                    Debug.Print("ACP 521 sHandCards: '" + sHandCards);
                    Debug.Print("ACP 522 MyForm.sRufAs: '" + MyForm.sRufAs + "'");

                    if (SearchInCardsPanel(11, CardsPanel) is not null)
                    {
                        Debug.Print("ACP 523 SearchInCardsPanel: '" + SearchInCardsPanel(11, CardsPanel).CardShortName + " " + SearchInCardsPanel(11, CardsPanel).CardSymbol + "'");
                        Debug.Print(SearchInCardsPanel(11, CardsPanel).CardShortName);
                        Debug.Print(SearchInCardsPanel(11, CardsPanel).CardSymbol);
                       
                        CurrentCard = SearchInCardsPanel(11, CardsPanel);
                        Debug.Print("ACP 527 CurrentCard: '" + CurrentCard.CardShortName + " " + CurrentCard.CardSymbol);

                        return CurrentCard;
                    }
                }
                // CurrentCard Is Nothing 
                if (Conversions.ToBoolean(Operators.ConditionalCompareObjectGreater(cpc.Count, 0, false)) && CurrentCard is null)
                {
                    for (int n = 0, loopTo4 = Conversions.ToInteger(Operators.SubtractObject(cpc.Count, 1)); n <= loopTo4; n++)
                    {
                        PlayingCard pc = (PlayingCard)CardsPanel.Children[n];
                        if (String.Equals(MyForm.sRufAs, pc.CardShortName + " " + pc.CardSymbol))
                        {
                            if (GameStatus.ToString() != "FirstCardInTrick")
                            {
                                CurrentCard = (PlayingCard)cpc[n];
                                Debug.Print("ACP 549 CurrentCard: '" + CurrentCard.CardShortName + " " + CurrentCard.CardSymbol);
                            }
                        }
                    }
                }
                if (Conversions.ToBoolean(Operators.ConditionalCompareObjectGreater(cpc.Count, 0, false)) && CurrentCard is null)
                {
                    for (int n = 0, loopTo4 = Conversions.ToInteger(Operators.SubtractObject(cpc.Count, 1)); n <= loopTo4; n++)
                    {
                        CurrentCard = (PlayingCard)cpc[n];
                        Debug.Print("ACP 555 CurrentCard: '" + CurrentCard.CardShortName + " " + CurrentCard.CardSymbol);
                    }
                }
            }
            Debug.Print("ACP 558 CurrentCard: '" + CurrentCard.CardShortName + " " + CurrentCard.CardSymbol);
            return CurrentCard;
        }


What I have tried:

when testing I got this result:
ACP 558 CurrentCard: '9 ♥

This comes from the end of my method:
Debug.Print("ACP 558 CurrentCard: '" + CurrentCard.CardShortName + " " + CurrentCard.CardSymbol);

This means one of the debug.print lines in the code before should fire - but does not.

What's wrong with my debug.print lines?
Posted
Updated 26-Jun-22 7:22am
Comments
Graeme_Grant 26-Jun-22 10:53am    
Set breakpoints on each debug.print to ensure that they are being hit. More likely than not, it is your logic that is preventing the code being reached.
Richard MacCutchan 26-Jun-22 10:55am    
All the other Debug.Print statements are within if blocks, so there may be good reasons why they have not fired. You need to use your debugger to find out why.

Here's one example that will never print (from the code above). I suggest there are other conditions that "stepping through" would clear up.

return CurrentCard;
Debug.Print("ACP 488 CurrentCard: '" + CurrentCard.CardShortName + " " + CurrentCard.CardSymbol);
 
Share this answer
 
Comments
Jo_vb.net 26-Jun-22 11:16am    
That's true.

Changed this and found two other if / else statements where debug.print line was missing.

Thank you.
Probably it hit one of the other return statements in that method - but the only way to find out is to run that code under the debugger and look at exactly what is going on while it is executing.

Adding Debug.Print liens is very "old school" debugging - most of us stopped doing that a couple of decades ago as debuggers became integrated into IDEs and became pretty much indispensable. I still use logging to help find production problems where I can't use a debugger, but 99% of the rest of my diagnosis is done with the debugger!
Modern debugger will let you see the content of variables, change which line is executed next, and even edit the code and continue the debugging session!

Put a breakpoint on the first line of the method, and run your app. When it reaches the breakpoint, the debugger will stop, and hand control over to you. You can now run your code line-by-line (called "single stepping") and look at (or even change) variable contents as necessary (heck, you can even change the code and try again if you need to).
Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?
Hopefully, that should help you locate which part of that code has a problem, and what the problem is.
 
Share this answer
 
The Debug statements will ALWAYS run. There is nothing that will prevent this, except your code.

This comes up often enough to mention this. Use the debugger! I cannot stress this enough! The debugger is there not to debug the code, but to debug YOU! It's there to help you understand how the code is working with the data you've given it. Stepping through the code line-by-line while it's executing and examining the content of variables before and after each statement executes is invaluable(!!) to you learning how this stuff works and understanding what you wrote.
 
Share this answer
 
Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

Debugging C# Code in Visual Studio - YouTube[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900