Share via

Some codes are not well called (or run)

Scott Huang 3,451 Reputation points
2026-05-04T08:08:15.31+00:00

Hi,

Running against the file below

https://1drv.ms/u/c/17ec75244bac022f/IQDksn7oBvAGSqa3I9pz8_dKAapU4-FWHovxVRFlkwrT5Tg?e=QdVOsH

the codes like

                                    if (cnt32 == 38 || cnt32 == 41 || cnt32 == 42)

                                    {

                                        sw.WriteLine("Please check No. of ^ delimiter (there are " + cnt32.ToString().Trim() + " ^ now; should be 27 or 37 ^ to a L+ line) below.");

                                        sw.WriteLine(str31); sw.WriteLine("");

                                        b_err3 = true;

                                    }

are not showing the messages to the text file. Is it possible that I put my program for anyone to have a look?

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


2 answers

Sort by: Most helpful
  1. Senthil kumar 110 Reputation points
    2026-05-04T08:55:40.6333333+00:00

    Hi Scott Huang,

    writer should be close after your text writing. then only updated in text.

     if (cnt32 == 38 || cnt32 == 41 || cnt32 == 42)     
     {
        sw.WriteLine("Please check No. of ^ delimiter (there are " + cnt32.ToString().Trim() + " ^ now; should be 27 or 37 ^ to a L+ line) below.");        
        sw.WriteLine(str31); 
        sw.WriteLine("");                                          
         b_err3 = true;                                      
     }
    
    sw.Close();
    
    

  2. Q&A Assist
    2026-05-04T08:08:34.9433333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The if block shown only executes when cnt32 is exactly 38, 41, or 42. If the message is never written, then at runtime cnt32 is not taking any of those values when that code is reached.

    To verify and debug:

    1. Add a temporary log of cnt32 just before the if:
         sw.WriteLine($"DEBUG: cnt32 = {cnt32}");
         if (cnt32 == 38 || cnt32 == 41 || cnt32 == 42)
         {
             sw.WriteLine("Please check No. of ^ delimiter (there are " + cnt32.ToString().Trim() + " ^ now; should be 27 or 37 ^ to a L+ line) below.");
             sw.WriteLine(str31);
             sw.WriteLine("");
             b_err3 = true;
         }
      
      Then inspect the output file to see what values cnt32 actually has.
    2. Ensure cnt32 is computed correctly and not reset or changed between counting delimiters and this if block.
    3. Confirm that sw is the same StreamWriter instance used for the rest of the file and that it is not disposed or closed before this code runs.
    4. If this code is inside a loop or conditional, verify that the loop/condition is actually reached for the lines in question.

    If after logging cnt32 the values are as expected (38, 41, or 42) but the message still does not appear, then the issue is likely elsewhere in the control flow (for example, the code path not being executed, or the file being overwritten later). In that case, step through the code with a debugger and set a breakpoint on the if (cnt32 == 38 || cnt32 == 41 || cnt32 == 42) line to confirm whether execution reaches it.


    References:

Your answer

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