September 14, 2002

Multitasking in a serial world

Many applications can benefit from using lazy processes or running routines in the background inside a single VB application. Designing a TaskThat was the fifty cent tour of what the TaskMster does, and you are welcome to look over the documented code, but the majority of your attention will be

Hex – Convert from decimal to hexadecimal

‘ convert from decimal to hexadecimal’ if you pass the Digits argument, the result is truncated to that number of ‘ digits” you should always specify Digits if passing negative valuesFunction Hex(ByVal value As Long, Optional ByVal digits As Short = -1) As String ‘ convert to base-16 Dim res

IsValidEmail – Validate an email address

Function IsValidEmail(ByVal Value As String, Optional ByVal MaxLength As _ Integer = 255, Optional ByVal IsRequired As Boolean = True) As Boolean If Value Is Nothing OrElse Value.Length = 0 Then ‘ rule out the null string case Return Not IsRequired ElseIf Value.Length > MaxLength Then ‘ rule out values

KeepInRange – Ensure that a value is in a given range

‘ Keep the first argument in the range [lowLimit, highLimit]’ If the value is adjusted, the fourth (optional) argument is set to True” This function works will all basic data types and with objects ‘ that implement the IComparable interfaceFunction KeepInRange(ByVal value As Object, ByVal lowLimit As Object, _ ByVal

CompareList – Compare an argument with a list of values

‘ Return the position of the argument in a list of values’ or zero if the argument isn’t included in the list’ It works for both regular values and for objects” This handy function can often save you a lengthy Select Case’ statement or a complex series of If…ElseIf blocks”

Hex2Dec – Convert from hexadecimal to decimal

‘ convert from hexadecimal to decimalFunction HexToDec(ByVal value As String) As Long ‘ we just need a call to the Convert.ToInt64 static method Return Convert.ToInt64(value, 16)End Function