Type-o-matic Text Box

Type-o-matic Text Box

This code creates a smart input box. Every time you type something into this text box, the first letters of your string are compared against the members of a hidden list box. The code guesses how your string should be completed and finishes it for you, similar to how the latest versions of Microsoft Excel and Internet Explorer behave.

To use this technique, add a list box to your form and set its Visible property to False. This example fills the list at Form_Load with some likely selections. In a real app, you’d add a new element to the list after each user entry is completed. Add this code to the form containing the text and list boxes:

 Option Explicit#If Win32 Then	Private Const LB_FINDSTRING = &H18F	Private Declare Function SendMessage Lib _		"User32" Alias "SendMessageA" (ByVal _		hWnd As Long, ByVal wMsg As Long, _		ByVal wParam As Long, lParam As Any) _		As Long#Else	Private Const WM_USER = &H400	Private Const LB_FINDSTRING = (WM_USER + 16)	Private Declare Function SendMessage Lib _		"User" (ByVal hWnd As Integer, ByVal _		wMsg As Integer, ByVal wParam As _		Integer, lParam As Any) As Long#End IfPrivate Sub Form_Load()	List1.AddItem "Orange"	List1.AddItem "Banana"	List1.AddItem "Apple"	List1.AddItem "Pear"End SubPrivate Sub Text1_Change()	Dim pos As Long	List1.ListIndex = SendMessage( _		List1.hWnd, LB_FINDSTRING, -1, ByVal _		CStr(Text1.Text))	If List1.ListIndex = -1 Then		pos = Text1.SelStart	Else		pos = Text1.SelStart		Text1.Text = List1		Text1.SelStart = pos		Text1.SelLength = Len(Text1.Text) - pos	End IfEnd SubPrivate Sub Text1_KeyDown(KeyCode As _	Integer, Shift As Integer)	On Error Resume Next	If KeyCode = 8 Then 'Backspace 		If Text1.SelLength <> 0 Then			Text1.Text = Mid$(Text1, 1, _				Text1.SelStart - 1)			KeyCode = 0		End If	ElseIf KeyCode = 46 Then 'Del		If Text1.SelLength <> 0 And _			Text1.SelStart <> 0 Then			Text1.Text = ""			KeyCode = 0		End If	End IfEnd Sub
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing