Solved

search for a string in an array

Posted on 2004-09-23
2
181 Views
Last Modified: 2010-05-02
I have an array of strings
now I want to search  the array for a specific string or a part of a string. I just want to know where in the array the string is.

thanks in advance
0
Comment
Question by:n96radsb
2 Comments
 
LVL 18

Accepted Solution

by:
JR2003 earned 50 total points
ID: 12135650
Private Sub Command1_Click()
    Dim i As Long
    Dim MyArray As Variant
    MyArray = Array("asd", "qwe", "xyz", "asd", "dfgxyzasd")
    For i = LBound(MyArray) To UBound(MyArray)
        If InStr(MyArray(i), "xyz") > 0 Then
            MsgBox "Element " & i & " contains the string"
        End If
    Next i
End Sub

0
 
LVL 8

Expert Comment

by:rajaloysious
ID: 12135651
     Dim listItems(4) As String
      Dim searchstr As String
      Dim bFound As Boolean
     
      searchstr = "Fou"
      Dim anItem As Variant
      listItems = Array("One", "Two", _
         "Three", "Four", "Five")
      List1.Clear
      bFound = False
      For Each anItem In listItems
         If InStr(1, anItem, searchstr) Then
            bFound = True
            Exit For
         End If
         bFound = False
      Next
    If bFound Then
        MsgBox "Found"
    Else
        MsgBox " Not found"
    End If
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 55
I need help formating a date variable in my VB.Net application 2 53
Help me. 3 57
IF ELSE Statement in Excel Macro VBA 16 66
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question