With .NET (VB or C#) you can create your own functions and classes
that are called from GuiXT using the
CallVB
keyword. .NET is a Microsoft framework that provides an extensive
class library — including functions for date and time calculations,
text processing, database access, and much more. This makes it easy
to implement tasks in VB.NET or C# that would be cumbersome in
GuiXT alone.
VB.NET, C#, and other .NET Framework languages are largely
interchangeable — they all compile to the same intermediate language
and share the same class library. If you encounter an example or
documentation that only shows code in one language, you can assume the
same approach works in the other with minor syntactic adjustments.
Throughout this documentation, examples are provided for both VB.NET
and C# where possible, but any concept shown in only one language
applies equally to the other.
In this example we show how to validate, parse, and modify dates
using .NET. The GuiXT script builds the following screen:
The user enters a date in the Date field. The three buttons
then perform the following actions:
Validate – checks whether the entered date is valid in
one of the supported formats.
Parse Date – returns the date in written-out form
(e.g. "Monday, January 5, 2025").
Add/Subtract Time – adds or subtracts days, months, and
years from the entered date and displays the result in the
New Date field.
The corresponding .NET class DateHandler in the namespace
Introduction contains three functions. First, an array with
all supported date formats is defined — from yyyyMMdd
to German (dd.MM.yyyy) and American
(MM/dd/yyyy) notation. This array is shared by all
three functions:
Imports System.Globalization
Namespace Introduction
Public Class DateHandler
Private Shared ReadOnly valid_date_formats As String() = {
"yyyyMMdd",
"yyyy-MM-dd",
"yyyy-MM-d",
"yyyy-M-dd",
"yyyy-M-d",
"dd.MM.yyyy",
"d.MM.yyyy",
"dd.M.yyyy",
"d.M.yyyy",
"MM/dd/yyyy",
"M/d/yyyy",
"MM/d/yyyy",
"M/dd/yyyy"
}
' ... functions follow below ...
End Class
End Namespace
using System;
using System.Globalization;
namespace Introduction
{
public class DateHandler
{
static readonly string[] valid_date_formats =
{
"yyyyMMdd",
"yyyy-MM-dd",
"yyyy-MM-d",
"yyyy-M-dd",
"yyyy-M-d",
"dd.MM.yyyy",
"d.MM.yyyy",
"dd.M.yyyy",
"d.M.yyyy",
"MM/dd/yyyy",
"M/d/yyyy",
"MM/d/yyyy",
"M/dd/yyyy"
};
// ... methods follow below ...
}
}
IsValidDate uses DateTime.TryParseExact to check
the given date against every entry in the format array. If the
function returns True, the date is valid. In VB.NET the
output value is captured in a temporary variable (dummy),
since no discard operator like C#'s out _ is available:
Public Function IsValidDate(ByVal dateStr As String) As Boolean
Dim dummy As DateTime
Return DateTime.TryParseExact(
dateStr,
valid_date_formats,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
dummy
)
End Function
public bool IsValidDate(string date)
{
return DateTime.TryParseExact(
date,
valid_date_formats,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out _
);
}
ParseDate also parses the date using TryParseExact
and, on success, returns it in written-out English form — e.g.
"Monday, January 5, 2025". If the date is invalid, an empty
string is returned:
Public Function ParseDate(ByVal input As String) As String
Dim parsedDate As DateTime
Dim ok As Boolean = DateTime.TryParseExact(
input,
valid_date_formats,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
parsedDate
)
If ok Then
Return parsedDate.ToString(
"dddd, MMMM d, yyyy",
New CultureInfo("en-US")
)
End If
Return ""
End Function
public string ParseDate(string input)
{
bool ok = DateTime.TryParseExact(
input,
valid_date_formats,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out DateTime date
);
if (ok)
{
return date.ToString(
"dddd, MMMM d, yyyy",
new CultureInfo("en-US")
);
}
return "";
}
ChangeDate iterates through the format array until the input
date can be successfully parsed. The specified days, months, and years
are then added — negative values subtract. The result is returned in
the same format in which the input date was recognised. Optional
parameters are declared in VB.NET with the Optional
keyword and a default value:
Public Function ChangeDate(ByVal input As String,
Optional ByVal days As Integer = 0,
Optional ByVal months As Integer = 0,
Optional ByVal years As Integer = 0) As String
For Each format As String In valid_date_formats
Dim parsedDate As DateTime
If DateTime.TryParseExact(input, format,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
parsedDate) Then
parsedDate = parsedDate.AddDays(days)
parsedDate = parsedDate.AddMonths(months)
parsedDate = parsedDate.AddYears(years)
Return parsedDate.ToString(
format, CultureInfo.InvariantCulture)
End If
Next
Return ""
End Function
public string ChangeDate(
string input, int days = 0, int months = 0, int years = 0)
{
foreach (var format in valid_date_formats)
{
if (DateTime.TryParseExact(
input, format,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out DateTime date))
{
date = date.AddDays(days);
date = date.AddMonths(months);
date = date.AddYears(years);
return date.ToString(
format, CultureInfo.InvariantCulture);
}
}
return "";
}
Before the class can be used in GuiXT, two requirements must be met:
Class library with .NET Framework: The project must be
compiled as a class library (DLL). The target framework must be
.NET Framework version 4.0 or higher — not .NET Core
or .NET 5+.
DLL directory: The compiled DLL must be copied into the
directory specified in the GuiXT profile for .NET class libraries
(VBDirectory). The interface library
guinet.dll (included in the GuiXT setup) must also
be present in this directory.
The three input scripts each call the .NET functions using
CallVB:
change_date.txt – missing values are set to "0" before
the call:
GuiXT
if V[days=]
Set V[days] "0"
endif
if V[months=]
Set V[months] "0"
endif
if V[years=]
Set V[years] "0"
endif
callvb rval = Introduction.DateHandler.ChangeDate "&V[inDate]" _
"&V[days]" "&V[months]" "&V[years]"
Set V[newDate] "&V[rval]"
The result of ChangeDate is written directly into the
New Date field. Empty fields for days, months, or years are
set to "0" before the call so that the .NET function receives a
valid integer value.