Case Statement Issue - 'hidden' CRLF in input stream?

Has anyone encountered this particular issue in Water/Fire with the Case Statement in Hydrogen(C#). It appears there may be some hidden character in the standard input stream that is tripping the Default statement to be evaluated (see attached pic)? I used a Trim function to strip any possible CRLF’s, but to no avail. I copied the program to VS C#, VS REMObjects C# as well as JetBrains Rider - and they all work as expected. The problem seems to be relegated to the Water and Fire IDE’s - they both exhibit the same behavior on my PC Desktop as well as on my MacBook Pro laptop.

namespace CaseStatementTest1
{
    static class Program
    {
        public static void Main(string[] args)
        {
           int totalAttempts = 3;
           string doorChoice;
           
           for (int i = 1 ; i <= totalAttempts; i++ )
           {
               Console.Write($"Choose a door between 1 - 5 and win a prize! This is attempt #{i}: ");
               doorChoice = Console.ReadLine();
               doorChoice = doorChoice.Trim(); // attempt to strip CRLF characters from input stream
               
               
               switch (doorChoice)
               {
                   case "1":
                       Console.WriteLine("You win a balloon!" );
                       break;
                   case "2":
                       Console.WriteLine("You win a stuffed animal!" );
                       break;
                   case "3":
                       Console.WriteLine("You win a bicycle!" );
                       break;
                   case "4":
                       Console.WriteLine("You win a car!" );
                       break;
                   case "5":
                       Console.WriteLine("You win a million dollars!" );
                       break;
                   default:
                       Console.WriteLine("That's not even a choice. You win nothing!" );
                       break;
               }
               Console.WriteLine();
           }
           Console.ReadLine();
           Console.ReadLine(); //Two needed in Fire/Water to prevent Terminal from prematurely closing
        }
    }
}

Curious; I’d love to hear what it turns out the problem was, here?

Hey Marc, I posted a bit too prematurely. So, I’m doing some more research on this lovely Spring-forward Sunday to narrow the problem down … :nerd_face:

1 Like

OK, I believe I’ve narrowed it down. The issue seems to occur when the code is generated using the “Template: Console Application (Windows) - RemObjects.Hydrogene.Island.Windows.ConsoleApplication”.

Here’s a Dropbox link: CaseStatement using Windows Console

The Case Statement code runs as expected when using the Classic_Net framework template.

2021-03-14 14_51_14-C__Users_chike_Documents_RemObjects Software_Elements_Water_CaseStatementNETClas

Here’s a Dropbox link: CaseStatement using Classic_Net

Also, of note, is that the Windows Console program requires two ‘Console.ReadLine()’ methods to prevent the Terminal from prematurely closing. As where, the Classic_Net program only requires one 'Console.ReadLine() which leads me to believe there’s an errant CRLF somewhere in the Windows Console version. :nerd_face:

1 Like

Will have a look in the morning, thanx!

1 Like

This sounds like a bug in ReadLine on Island/Windows (or Island in general), yeah…

FWIW, on Mac I can not reproduce this, I changed your code to::

           writeLn(1);
           Console.ReadLine();
           writeLn(2);
           //Console.ReadLine(); //Two ReadLines needed to prevent Terminal from prematurely closing which leads me to believe there's a 'hidden' CRLF

and it emits “1”, I press enter once, and then it emits “2” and quits. Will test on Windows later in the day when I boot up my VM…

Side quesrtion: what version are you on, latest 2611? (not that think much changed here in the past few weeks that would effect this…)

Definitely something flaky, I get this:

I press 1 once, and the “not a valid choice” comes as a second message right away. I then press ` again and it exits right away.

It seems where you get one too few enters, I get too many…

Thanks, logged as bugs://85726

yep, “1”

results in two readlines, one with “1” and one empty:"

1 Like

Hey Marc, I’m using version .2605 Water and .2611 Fire. Thank you for looking into this and I’m glad you were able to confirm the issue. Cheers :nerd_face:

Gary,

FWIW, I can repro the with .2611 on Windows too (was a few builds behind before), same as above. But I cannot reproduce this on Mac, When you say Fire, do you mean building the app as Island/macOS, or as Island/Windows and running remotely.?

For me, the issue seems specific to Windows.

That’s correct … I was running Parallels on my Mac. So composing in Fire but building for Island/Windows which executed in Windows Parallel. That’s why I stated I was a bit premature with my first post of this thread and narrowed it down to Island/Windows only :smile:

1 Like

bugs://85726 got closed with status fixed.

Sorry for the delay, the fix will be included in today’s build

1 Like