November 25, 2002

FindControlRecursive – Find a control in a hierarchy of controls

‘ Find a control in a hierarchy of controls’ Example:’ Dim txtCtl As Control = FindControlRecursive(DataGrid1, “FirstNameTextBox”)Function FindControlRecursive(ByVal ctrl As Control, _ ByVal id As String) As Control ‘ Exit if this is the control we’re looking for. If ctrl.ID = id Then Return ctrl ‘ Else, look in the

GetIndexFromValue – Return the index in a ListControl given a value

‘ Return the index in a ListControl given a value’ Example:’ Dim i As Integer = GetIndexFromText(ListBox1, “hellovalue”)Function GetIndexFromValue(ByVal lst As ListControl, ByVal value As String) As _ Integer Return lst.Items.IndexOf(lst.Items.FindByValue(value))End Function

GetIndexFromText – Return the index in a ListControl given a text

‘ Return the index in a ListControl given a text’ Example:’ Dim i As Integer = GetIndexFromText(ListBox1, “hello”)Function GetIndexFromText(ByVal lst As ListControl, ByVal value As String) As _ Integer Return lst.Items.IndexOf(lst.Items.FindByText(value))End Function

EvalFileName – Ensure that the basename of a file or directory is valid

‘ EvalFileName ensures that the basename of a file or directory’ conforms to the Microsoft file naming guidelines (see MSDN webpage)’ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/’ naming_a_file.asp” Return value:’ True = Valid basename’ False = Invalid basename” Note: Since EvalFileName checks only the basename of a file or’ directory, it does not test the

Using the CreateDirectory API function

The VB’s MkDir function creates a directory in a specified path. If the directory already exists, MkDir raises error 75 (Path/file access error); yet, it raises the same error code if you attempt to create the directory on a read-only drive. Even worse, in Windows NT/2K/XP workstations, if you try

Using multiple fields as value for the DropDownList control’s items

Being an avid Access Programmer I have been frustrated with the limitation of VB DropDownLists to using only 1 field as the value. I found a way to simulate/work around this behavior with concatenation of several database fields at the query level to be my columns(i.e. Select KeyId1 + ‘~’