if anybody knows how to apply searching in VB6.0 ,please let me know.

Dani AI

Generated

As asked and as and hinted, the first step is deciding what you are searching (a database, an in-memory list, or files) and what kind of search you need (exact match, partial substring, starts-with, or pattern/regex). The implementation in VB6 is very different for each case, so clarifying that will save time.

For database lookups use ADO and run the search on the server (SQL WHERE) whenever possible. Parameterized queries avoid injection and handle quoting safely. Example (add a reference to Microsoft ActiveX Data Objects):

' Requires reference to Microsoft ActiveX Data Objects x.x Library
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim searchText As String

searchText = "Smith"

Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;Data Source=SERVER;Initial Catalog=DB;Integrated Security=SSPI;"

Set cmd = New ADODB.Command
Set cmd.ActiveConnection = cn
cmd.CommandText = "SELECT * FROM Customers WHERE CompanyName LIKE ?"
cmd.CommandType = adCmdText
cmd.Parameters.Append cmd.CreateParameter("p1", adVarChar, adParamInput, 255, "%" & searchText & "%")

Set rs = cmd.Execute

For small in-memory searches use InStr in a loop or Recordset.Find for an open recordset. Example scanning an array:

Dim i As Long
For i = LBound(arr) To UBound(arr)
  If InStr(1, arr(i), searchText, vbTextCompare) > 0 Then
    ' match found: arr(i)
  End If
Next i

Practical notes: use server-side indexes or full-text search for large tables; confirm the wildcard style your provider expects (% for most SQL providers; legacy Access modes sometimes expect *); escape single quotes when concatenating SQL or, better, use parameters; and for pattern searches consider the VBScript.RegExp library. If the target is a file system, use Dir or FileSystemObject to enumerate files and then search file contents with InStr.

Recommended Answers

All 2 Replies

if anybody knows how to apply searching in VB6.0 ,please let me know.

exactly what dbase are you going to use and what kind of searching do you wanT???

if anybody knows how to apply searching in VB6.0 ,please let me know.

please specify what data to be searched... you don't have an MSDN in your computer? there's a lot out there or try here http://www.vbtutor.net/vbtutor.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.