Skip to content

Console Log and User Interaction

Function: IsCancellationRequested

bool IsCancellationRequested()
Description:
Determines if the user has requested a cancellation. It is recommended to be used inside the loops to determine the exit point at the request of the user.

Parameters:
None.

Returns:
- true if a cancellation was requested.
- false otherwise.

Usage Example
1
2
3
4
5
if(IsCancellationRequested())
{
    PrintLine("Operation was cancelled by the user.");
    return;
}

Function: Clear

void Clear()

Description:
Clears the console output, removing all text and setting the cursor back to the top-left corner of the console window.

Parameters:
None

Return Value:
None

Usage Example
1
2
3
4
PrintLine("This is some text that will be cleared.");
Sleep(2000);  // Sleep for 2 seconds
Clear();  // Clears the console
PrintLine("The console is now clear.");

Procedure: Print and PrintLine

void Print(params object[] objects)
void PrintLine(params object[] objects)
Description:
Prints the specified text to the console. This function not only supports basic text but also handles arrays of strings and tuples for enhanced data visualization. Procedure PrintLine is similar to the Print procedure, but appends a newline character at the end to move the caret to a new line.

Parameters:
- objects: An array of objects to be printed. This could include text, numbers, arrays of strings, or tuples.

Returns:
None.

Usage Example
PrintLine("This is a sample message for demonstration purposes.");

var str = "another string";
PrintLine($"Here are {str} inside."); // Will print: Here are another string inside.

byte singleByte = 255;
PrintLine($"HEX value of singleByte is: {singleByte:X2}"); // Will print: HEX value of singleByte is: FF

// Print multiple objects
PrintLine("Temperature:", 37, "°C");

// Print an array of strings
string[] fruits = new string[] { "Apple", "Banana", "Cherry" };
PrintLine(fruits);

// Print a tuple
var person = ("John", 30);
PrintLine(person);

// Print a complex combination
PrintLine("Person Info:", person, "Fruits:", fruits);

Function: SetTextColor

void SetTextColor(string argb)

Description:
Changes the text color for console output. The color is specified using an ARGB (Alpha, Red, Green, Blue) string format, starting with a # sign. To reset the text color to the default, you can pass an empty string or null.

Parameters:
- argb: The ARGB string specifying the desired text color. The string should start with a # sign. Pass an empty string or null to reset to the default text color.

Return Value:
None

Usage Example
1
2
3
4
5
Print("This is ");
SetTextColor("#FFFF0000");  // Sets the text color to red
Print("red");
SetTextColor(null); // Sets the text color to default GreenYellow
Print(" text.");

Function: SelectFromList

int SelectFromList(string message, params string[] items)
Description:
Displays a selection list to the user and returns the selected index. Can be used as a choice from a list of values, or as a dialog where more than 1 option is offered.

Parameters:
- message: The message to display above the list.
- items: A list of string items for the user to select from.

Returns:
- Index of the selected item, or -1 if cancelled.

Usage Example 1
1
2
3
4
5
6
string[] options = {"Option 1", "Option 2", "Option 3"};
int selectedIndex = SelectFromList("Please select an option:", options);
Print($"User selected: {options[selectedIndex]}");
// Option 1 = 0
// Option 2 = 1
// Option 3 = 2
Usage Example 2
int selectedIndex = SelectFromList("Do you want to continue?", "Yes", "No");
if (selectedIndex == -1)
{
    Print("You selected to Cancel");
    return;
}
if (selectedIndex == 0) // Yes
{
    Print("You selected Yes");
}
if (selectedIndex == 1) // No
{
    Print("You selected No");
}

Function: InputBox

string InputBox(string message, string defaultText = "")
Description:
Prompts the user to input a text value.

Parameters:
- message: The message to display to the user.
- defaultText: Optional parameter to set the default text value.

Returns:
- User input as a string.

Usage Example 1
string userInput = InputBox("Please enter your name:");
PrintLine($"Hello, {userInput}!");
Usage Example 2
1
2
3
4
5
6
7
8
string userInput = InputBox("Please enter your age:", "99");
if (!string.IsNullOrEmpty(userInput) && int.TryParse(userInput, out var intAge))
{
    PrintLine($"Your age is: {intAge}");
}else
{
    PrintLine("Incorrect input");
}

Procedure: ShowMsg

void ShowMsg(string message, bool isError = false)
Description:
Displays a message to the user. Can differentiate between standard messages and error messages.

Parameters:
- message: The message to be displayed.
- isError: Optional parameter to specify if the message is an error. Defaults to false.

Returns:
None.

Usage Example
ShowMsg("This is a standard message.");
ShowMsg("This is an error message!", true);

Function: GetUserName

string GetUserName()
Description:
Retrieves the current user's VCTool login. Can be used to control access to an application at the source code level. Attention: such verification is not allowed in publishing applications.

Parameters:
None.

Returns:
- Name of the current user VCTool login as a string.

Usage Example
string username = GetUserName();
PrintLine($"Logged in as: {username}");

Progress panel

Procedure: ShowWorkingPlate

void ShowWorkingPlate(bool show)
Description:
Displays or hides a working plate over the log window to indicate a process in progress. The working plate contains a text field and a progress bar.

Parameters:
- show: Boolean value determining if the working plate should be shown (true) or hidden (false).

Returns:
None.

Usage Example
1
2
3
4
ShowWorkingPlate(true);
PrintLine("Processing data...");
// some processing code here
ShowWorkingPlate(false);

Function: InitProgressBar

void InitProgressBar(long maximum)
Description:
Initializes a progress bar on the working plate with a specified maximum value.

Parameters:
- maximum: The maximum value for the progress bar.

Returns:
None.

Usage Example
InitProgressBar(100);
PrintLine("Starting data transfer...");

Function: SetProgressBarValue

void SetProgressBarValue(long value)
Description:
Sets the current value of the progress bar.

Parameters:
- value: The value to which the progress bar should be set.

Returns:
None.

Usage Example
1
2
3
4
5
for(long i = 0; i <= 100; i++)
{
    SetProgressBarValue(i);
    Sleep(50); // simulating work
}

Function: IncreaseProgressBarValue

void IncreaseProgressBarValue(long step = 1)
Description:
Increases the value of the progress bar by a specified step.

Parameters:
- step: The amount by which the progress bar value should be increased. Default is 1.

Returns:
None.

Usage Example
1
2
3
4
5
6
InitProgressBar(100);
for(long i = 0; i < 100; i++)
{
    IncreaseProgressBarValue();
    Sleep(50); // simulating work
}

Function: SetWorkingPlateText

void SetWorkingPlateText(string text)
Description:
Updates the text displayed on the working plate.

Parameters:
- text: The text to be displayed on the working plate.

Returns:
None.

Usage Example
1
2
3
4
5
6
ShowWorkingPlate(true);
SetWorkingPlateText("Loading data...");
// some loading code here
SetWorkingPlateText("Processing data...");
// some processing code here
ShowWorkingPlate(false);