Skip to content

Script Functions Reference

When you write VBA code inside VBA Padlock’s code editor (the scripts that get compiled into the DLL), you have access to a set of built-in functions beyond standard VBA.


The extension library provides VBA-compatible functions that work inside compiled scripts. These mirror standard VBA functions so you can write natural VBA code.

All string functions support the VBA $ suffix variants (e.g., Mid$, Left$, Trim$) which return String instead of Variant.

Function Mid(S As String, Start As Integer, Optional Length As Integer) As String

Returns a substring starting at Start (1-based).

Function Left(S As String, Length As Integer) As String
Function Right(S As String, Length As Integer) As String

Returns the leftmost or rightmost Length characters of a string.

Function Len(S As String) As Integer

Returns the number of characters in a string.

Function InStr(Start As Integer, String1 As String, String2 As String, Optional Compare As Integer = vbBinaryCompare) As Integer
Function InStrRev(StringCheck As String, StringMatch As String, Optional Start As Integer = -1, Optional Compare As Integer = vbBinaryCompare) As Integer

Returns the position of the first (or last) occurrence of a substring. Returns 0 if not found.

Function Replace(Expression As String, Find As String, ReplaceWith As String, Optional Start As Integer = 1, Optional Count As Integer = -1, Optional Compare As Integer = vbBinaryCompare) As String

Replaces occurrences of a substring within a string. Set Count to limit the number of replacements.

Function Trim(S As String) As String
Function LTrim(S As String) As String
Function RTrim(S As String) As String

Removes leading and/or trailing spaces from a string. LTrim removes leading spaces only, RTrim trailing spaces only.

Function UCase(S As String) As String
Function LCase(S As String) As String

Converts a string to uppercase or lowercase.

Function Split(Expression As String, Optional Delimiter As String = " ", Optional Limit As Integer = -1, Optional Compare As Integer = vbBinaryCompare) As Variant
Function Join(SourceArray As Variant, Optional Delimiter As String = " ") As String

Split breaks a string into an array of substrings using a delimiter. Join concatenates an array of strings into a single string.

Function Like(S As String, Pattern As String) As Boolean

Pattern matching. Wildcards: ? (any character), * (any characters), # (any digit), [charlist] (character list).

Function Format(Expression As Variant, Optional FormatStr As String = "") As String

Formats a number, date, or string according to a format specifier (e.g., "#,##0.00", "yyyy-mm-dd").

FunctionSignatureDescription
AbsAbs(X) As DoubleAbsolute value
SqrSqr(X) As DoubleSquare root
Sin, Cos, TanTrigonometric functionsSine, Cosine, Tangent (radians)
ExpExp(X) As DoubleExponential (e^X)
RoundRound(X, Optional Digits = 0) As DoubleArithmetic rounding
ValVal(S As String) As DoubleParse string to number
StrStr(X) As StringNumber to string
Function Now() As Double
Function Date() As Double
Function Time() As Double

Now returns the current date and time. Date returns the date portion only. Time returns the time portion only. All values are VBA Date-compatible doubles.

Function DateAdd(Interval As String, Number As Integer, DateValue As Double) As Double
Function DateDiff(Interval As String, Date1 As Double, Date2 As Double, ...) As LongLong

DateAdd adds a time interval to a date (e.g., DateAdd("m", 3, Now()) adds 3 months). DateDiff returns the number of intervals between two dates. Supported intervals: "yyyy" (year), "q" (quarter), "m" (month), "d" (day), "h" (hour), "n" (minute), "s" (second).

Function IIf(Expression As Boolean, TruePart As Variant, FalsePart As Variant) As Variant
Function Choose(Index As Integer, Choice1, ...) As Variant
Function Switch(Expr1, Value1, ...) As Variant

Inline conditional functions. IIf returns one of two values based on a condition. Choose returns a value from a list based on an index. Switch evaluates expression/value pairs and returns the value for the first True expression.

FunctionSignatureDescription
ArrayArray(args...) As VariantCreates a 0-based array
DoEventsDoEvents() As IntegerProcesses pending Windows messages
TypeNameTypeName(V) As StringReturns the type name of a variable
VarTypeVarType(V) As IntegerReturns the type code of a variable
NzNz(Value, Optional Default = 0) As VariantReturns Default if Value is Null or Empty
RGBRGB(Red, Green, Blue) As IntegerCreates a color value

These functions let your compiled scripts interact with the licensing system at runtime.

Function IsLicenseValid() As Boolean

Returns True if the current license is valid or if activation is not required.

Function IsTrialMode() As Boolean

Returns True if the application is currently running in trial mode.

Function HasStoredLicense() As Boolean

Returns True if a license key is stored on this computer.

Function GetTrialDaysLeft() As Integer

Returns the remaining trial allowance. Returns -1 if not in trial mode.

Function GetTrialLimitType() As Integer

Returns the type of trial limit configured for this project.

ReturnMeaning
0Days (tltDays)
1Runs (tltRuns)
2Expiration date (tltExpiration)
-1Not in trial mode
Function GetRegisteredName() As String

Returns the licensee name, or an empty string if no license is stored.

Function GetHardwareID() As String

Returns the Hardware ID string for the current machine.

Function GetLicenseProperty(PropertyName As String, Optional DefaultValue As Variant = "") As Variant

Returns a project or license property by name.

Property NameDescription
registerednameLicensee name
licensekeyStored license key
apptitleApplication title
projectguidProject unique identifier
purchaseurlPurchase URL (configured in VBA Padlock Studio)

Example:

Dim title As String
title = GetLicenseProperty("apptitle", "My App")

VBA Padlock provides built-in dialogs that you can trigger directly from your scripts.

Function ShowActivationDialog(Optional ForceDisplay As Boolean = False) As Integer

Displays the activation dialog. Returns 1 on success, 0 on cancel.

Activation Dialog

Function ShowTrialNag(Optional ForceDisplay As Boolean = False) As Integer

Shows the trial nag screen. Returns 0 (continue), 1 (activate), or 2 (purchase).

Trial Nag Screen

Function ShowDeactivateDialog() As Integer

Shows the deactivation dialog. Returns 0 on success, 1 on cancel.

Function ShowEULA(Optional ForceDisplay As Boolean = False) As Integer

Displays the EULA dialog. Returns 1 (accepted), 0 (declined).

EULA Screen

Function IsEulaAccepted() As Boolean

Returns True if the EULA has been accepted or if no EULA is configured.

Function GetEulaAcceptanceDate() As Double

Returns the EULA acceptance date as a TDateTime value (VBA Date compatible). Returns 0 if not accepted.

Function ValidateOnline(Optional Silent As Boolean = True) As Integer

Performs online license validation against the activation server.

ReturnMeaning
1Validation successful
0Failed or license revoked
-1Not initialized
-2Online validation not configured
-3No license stored
-4Network error
-5Server error
-6Security validation failed

Example:

Dim result As Integer
result = ValidateOnline(False) ' Show errors to user
If result = 0 Then
MsgBox "Your license has been revoked.", vbCritical
End If
Function IsValidationRequired() As Integer

Returns 1 if an online validation check is due, 0 if not yet required.


These functions provide localization support for your compiled scripts. You can load custom translations from JSON files and use them in your code.

  1. Prepare a JSON file with your translations (e.g., {"welcome_message": "Bienvenue"}).
  2. Load the locale in your script using LoadLocale(jsonContent).
  3. Retrieve strings anywhere using L("key").
Function L(Key As String) As String

Returns the localized string for the given key. If the key is not found, returns the key itself.

Example:

MsgBox L("welcome_message")
Function LFmt(Key As String, Args As Variant) As String

Returns a formatted localized string with placeholder substitution (up to 5 arguments).

Example:

' If the locale defines: "greeting" = "Hello, %s! You have %d messages."
Dim msg As String
msg = LFmt("greeting", Array("John", 5))
' Result: "Hello, John! You have 5 messages."
Function LPlural(Key As String, Count As Integer) As String

Returns the appropriate plural form of a localized string based on the count.

Function LoadLocale(JSONContent As String) As Boolean

Loads localization strings from a JSON string. Returns True on success.

Function GetCurrentLocale() As String

Returns the current locale code (e.g., "en", "fr"), or an empty string if no locale is loaded.

Function IsLocaleLoaded() As Boolean

Returns True if a custom locale has been loaded.

Function HasLocaleKey(Key As String) As Boolean

Returns True if the given key exists in the current locale.

Function SetLocaleString(Key As String, Value As String) As Boolean

Adds or overrides a single locale string. Returns True on success.


ConstantValueDescription
vbUpperCase1Convert to uppercase
vbLowerCase2Convert to lowercase
vbProperCase3Capitalize first letter of each word
vbUnicode64Convert to Unicode
vbFromUnicode128Convert from Unicode