Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Feb 12, 2001

Simulate an Outlook Address Book Records Selection


This tip shows how to simulate the look of an Oultlook address book records selection.
  • Open a New VB Project and add a New Form with 1 Text Box and a List Box.
  • Copy this code and you are set to go:
  •  
    	Private Sub Text1_Change()
    	    
    	    Dim intI As Integer
    	    Dim strTmp As String
    	    
    	    strTmp = Text1.Text
    	    intI = MatchList(strTmp, List1) 'Call the Function
    	    
    	    If intI >= 0 Then
    	        List1.ListIndex = intI
    	        List1.TopIndex = intI
    	    End If
    
    	End Sub
    
    
    	Function MatchList(strIn As String, listIn As ListBox) As Integer
    	'------------------------------------------------------------
    	'Function to match the typed string from an existing list box
    	'NOTE : The list should be sorted
    	'------------------------------------------------------------
    
    	    Dim blnMatchFound As Boolean
    	    Dim intI As Integer
    	    Dim intstrLength As Integer
    	    Dim strFirstLetter As String
    	    
    	    intstrLength = Trim(Len(strIn))
    	    strFirstLetter = UCase(Left(Trim(strIn), 1))
    	    
    	    '*** Search for exact match ***
    	    For intI = 0 To listIn.ListCount - 1
    	     If Left(UCase(listIn.List(intI)), intstrLength) Like
    UCase(strIn) Then
    	         blnMatchFound = True
    	         MatchList = intI
    	         Exit Function
    	     End If
    	    Next
    	    
    	    '*** Search for After/Before strings (if no match has been
    found) ***
    	    If blnMatchFound = False Then
    	        For intI = 0 To listIn.ListCount - 1
    	          If Left(UCase(listIn.List(intI)), 1) >
    UCase(strFirstLetter) Then
    	              blnMatchFound = True
    	              MatchList = intI
    	              Exit Function
    	          Else
    	              blnMatchFound = True
    	              MatchList = intI
    	          End If
    	        Next
    	    End If
    	    
    	End Function
    
    
    	Private Sub Form_Load()
    
    	    List1.AddItem 
    Venkat Alladi
     
    Comment and Contribute

     

     

     

     

     


    (Maximum characters: 1200). You have 1200 characters left.

     

     

    Sitemap
    Thanks for your registration, follow us on our social networks to keep up-to-date