October 6, 2003

SetPropertyEx – Set a property of multiple controls/objects

‘ Set a property of multiple controls/objects in a single step,’ and return True if successful’ Note: requires the SetProperty function” Example: SetPropertyEx(“Text”, “OK!!!”, TextBox1, Button1, Button2)Function SetPropertyEx(ByVal propertyName As String, ByVal val As Object, _ ByVal ParamArray objs() As Object) As Boolean Dim obj As Object Try For Each

GetRandomArrayItem – Return a random item from an array or collection

‘ Return a random item from a mono/bi/tri-dimensional array or collection’ ‘ Example:’ Dim arr1 As String() = {“this is string 0”, “this is string 1”,’ ‘ “this is string 2”, “this is string 3”, “this is string 4”}’ Dim i As Integer’ For i = 1 To 10′ Debug.WriteLine(GetRandomArrayItem(arr1))’

GetTextBoxCurrentLine – Determine the current line in a multiline TextBox control

Shared Function _ SendMessage(ByVal hWnd As Integer, ByVal wMsg As Integer, _ ByVal wParam As Integer, ByVal lParam As Integer) As IntegerEnd Function’ Determine the current line in a multiline TextBox control’ Example: MessageBox.Show(GetTextBoxCurrentLine(TextBox1))Function GetTextBoxCurrentLine(ByVal tb As TextBox) As Integer Const EM_LINEFROMCHAR As Integer = &HC9 Return SendMessage(tb.Handle.ToInt32(), EM_LINEFROMCHAR, -1,

HaveSameValue – Check whether all the input controls have the same property value

‘ Return True if all the controls in the input array have the same value for ‘ the specified property’ Note: requires the GetField function” Example:’ Debug.WriteLine(HaveSameValue(“Text”, TextBox1, Button1, Button2))’ Debug.WriteLine(HaveSameValue(“ForeColor”, Button1, Button2))’ Button1.ForeColor = Color.Yellow’ Debug.WriteLine(HaveSameValue(“ForeColor”, Button1, Button2))Function HaveSameValue(ByVal propertyName As String, ByVal ParamArray objs() As _ Object) As

GetControlsByTag – Find all the controls with the specified Tag value

‘ Find all the controls with the specified Tag value’ Example:’ Dim ctrls() As Control = GetControlsByTag(“OK”, Me)’ Dim ctrl As Control’ For Each ctrl In ctrls’ Debug.WriteLine(ctrl.Name)’ NextFunction GetControlsByTag(ByVal tagToSearch As String, _ ByVal parentControl As Control) As Control() Dim controlList As New System.Collections.ArrayList ‘ add the parent control

Enable a key-skipping mechanism for a TextBox

‘ Enable the key-skipping mechanism for the input TextBox and for the input ‘ chars’ Example: don’t process the ‘A’, ‘b’ and ‘0’ chars’ EnableTextBoxCharSkip(TextBox1, “A”c, “b”c, “0”c)Sub EnableTextBoxCharSkip(ByVal tb As TextBox, ByVal ParamArray keysToSkip() As _ Char) ‘ save the array of keys textbox’s Tag property tb.Tag = keysToSkip