• After more than 30 years running websites and forums I am retiring.

    I have made many friends through the years. I will cherish my time getting to know you. I wish you all the best. This was not an easy decision to make. The cost to keep the communities running has gotten to the point where it's just too expensive. Security certificates, hosting cost, software renewals and everything else has increased threefold. While costs are up ad revenue is down. It's no longer viable to keep things running.

    All sites will be turned off on Thursday 30 November 2023. If you are interested in acquiring any of the websites I own you can Email Schwarz Network.

I want to adapt or transform from C# code to F#.

M

Metaconta

Guest
Hello:
I want to adapt or transform from C# code to F#.

Code C#:

using System;

namespace radioButton_consola_02_cs
{
class Program
{
#region Variables.
private static readonly string[] TEXTO = new string[]
{
"( ) Option A ",
"( ) Option B ",
"( ) Option C ",
" EXIT"
};

private static int itemSeñalado;

private static int itemSeleccionado;
#endregion

static void Main(string[] args)
{
// Window title.
Console.Title = "RadioButton";

// Window size.
Console.SetWindowSize(20, 5);

// Green background.
Console.BackgroundColor = ConsoleColor.Blue;

// Black letters.
Console.ForegroundColor = ConsoleColor.White;

// I hide the cursor.
Console.CursorVisible = false;

// Stores the key pressed in the variable.
ConsoleKey teclaInicial;

do
{
// Clean screen.
Console.Clear();

// Cursor position of the MAIN MENU title.
Console.SetCursorPosition(0, 0);

// Title.
Console.Write(" MENÚ PRINCIPAL ");

// Time position.
Console.SetCursorPosition(4, 2);

// Numeric format dd/MM/yyyy.
Console.Write(DateTime.Now.ToString("ddd dd MMM"));

// Stores a pressed key in the variable.
teclaInicial = Console.ReadKey(true).Key;

// Did you press the Enter key?
if (teclaInicial == ConsoleKey.Enter)
{
// Yes. This function is executed.
MenuPrincipal();
}
} while (teclaInicial != ConsoleKey.Escape);
}

#region Main menu.
private static void MenuPrincipal()
{
bool salir = false;

// In itemSelecionado:
// -1 = Not selected with * any option.
// 0 = Select with * Option A.
// 1 = Select with * Option B.
// 2 = Select with * Option C.

// Capture key and then validate.
ConsoleKey tecla;

// Every time you return to the menu, it is marked with the *.
itemSeñalado = 0;

do
{
//******************************************************************
// I draw the main menu.

// Clean screen.
Console.Clear();

for (int k = 0; k < TEXTO.Length; k++)
{
Console.SetCursorPosition(0, k);
Console.Write(itemSeñalado == k ? "> " : " ");
Console.Write(TEXTO[k]);
Console.SetCursorPosition(3, k);
Console.Write(itemSeleccionado == k ? "*" : " ");
}

// End of painting the main menu.
//******************************************************************

// Read key entered by user.
tecla = Console.ReadKey(true).Key;

switch (tecla)
{
case ConsoleKey.Enter:
if (itemSeñalado < 3)
{
itemSeleccionado = itemSeñalado;
}
salir = (itemSeñalado == TEXTO.Length - 1);
break;

case ConsoleKey.DownArrow:
if (++itemSeñalado >= TEXTO.Length)
{
itemSeñalado = 0;
}
break;

case ConsoleKey.UpArrow:
if (--itemSeñalado < 0)
{
itemSeñalado = TEXTO.Length - 1;
}
break;
}
// I use the escape key as output.
} while (!salir);
}
#endregion
}
}

Thank you.





Continue reading...
 
Top Bottom