July 28, 2003

IsKeyPressed – Check whether a key is pressed

Private Shared _ Function GetAsyncKeyState(ByVal key As Keys) As IntegerEnd Function’ Check whether a key is pressed, at any given time’ Example: MessageBox.Show(IsKeyPressed(Keys.A))Function IsKeyPressed(ByVal key As Keys) As Boolean Return GetAsyncKeyState(key) < 0End Function

GetMdacVersion – Retrieve the installed MDAC version

‘ Retrieve the installed MDAC version” Examples:’ Dim ver As Version = GetMdacVersion()’ ‘ print the full version’ MessageBox.Show(ver.ToString())’ ‘ print the major and minor portions’ MessageBox.Show(“Major: ” & ver.Major & “, Minor: ” & ver.Minor)’ ‘ check whether the current version is at least 2.7’ If ver.CompareTo(New Version(2, 7,

AddRemoveEventHandler – Add or remove an event handler through reflection

‘ Add or remove an event handler through reflection,’ and return True if successful” Examples:’ ‘ add an event handler for Button1’s Click event’ AddRemoveEventHandler(Button1, “Click”, New EventHandler(AddressOf ‘ OnButton1Click))’ ‘ remove an event handler for Button1’s Click event’ AddRemoveEventHandler(Button1, “Click”, New EventHandler(AddressOf ‘ OnButton1Click), False)Function AddRemoveEventHandler(ByVal obj As Object,

SetCommandsTransaction – Assign a transaction to the DataAdapter’s commands

‘ Assign the same transaction to the Update/Delete/Insert commands of all the ‘ OleDb/SqlAdapters passed in input’ Note: all the DataAdapters must be of the same type (OleDb or Sql)’ Note: requires Imports System.Data.OleDb and Imports System.Data.SqlClient” Example: SetCommandsTransaction(tran, da1, da1)Sub SetCommandsTransaction(ByVal tran As IDbTransaction, _ ByVal ParamArray adapters() As

EndsWith – Check whether a string ends with one of multiple possible choices

‘ Check whether a string ends with one of multiple possible choices.’ Return -1 if no possible string matches the end of the source,’ otherwise return the index of the matching string.” Examples:’ Debug.WriteLine(EndsWith(“This is my test line”, True, “Line”,’ “String”)) ‘ => -1’ Debug.WriteLine(EndsWith(“This is my test line”, True,

StartsWith – Check whether a string starts with one of multiple possible choices

‘ Check whether a string starts with one of multiple possible choices.’ Return -1 if no possible string matches the start of the source,’ otherwise return the index of the matching string.” Examples:’ Debug.WriteLine(StartsWith(“This is my test line”, True, “this”,’ “that”)) ‘ => -1’ Debug.WriteLine(StartsWith(“This is my test line”, True,