LocateField

The LocateField function may be used to find the index of a field, subfield, or sub-subfield within a dynamic array.

 

For example, if your string is: "Tom;32;England*Jane;29;Spain"

If you wanted to locate "32" with delim ";" the function will return 2 (the second field).

If you wanted for locate "England*Jane" with delim ";" the function will return 3 because they are considered 1 unit.

Note that the semicolon is ascii 59 and the asterisk is ascii 42.

The way the function operates is by searching the string on the designated character until it reaches an ascii character that has a lower value.

 

Group: DynamicArrayExt

Syntax: LocateField(ByVal Find as Variant, ByVal String as Variant, [Byval Delim]) as Variant

Find           (Variant) will return the index position of the sought after string/field.

String        (Variant) is the string value to be located.

[Delim]     (Variant) is the delimiter variable to be located.

Example:

Public dynArray As String

Dim i As Variant

Public Property Get delim(sign) As String

Dim v As Variant

v = Array(" ", "#", "@", "&")

delim = v(sign)

End Property

Private Sub btnLoc1_Click()

On Error Resume Next

If TextBox1.Text = "" Then

App.Balloon("Must have Field to find in Textbox", 1)

Exit Sub

End If

i = LocateField(TextBox1.Text, dynArray)

App.MsgBox(TextBox1.Text & " is at: " & i)

End Sub