'a function that works the same way as the Instr Function does.
'a function that works the same way as the Instr Function does.
Rate 'a function that works the same way as the Instr Function does.
(1(1 Vote))
'It looks for a character in a string or expression and returns
'the numeric character position in that string
'Very handy especially in database programming and query building.
'This function works the same way as Instr
'put one command button and one text box on your form
'see code below
Option Explicit
Private Sub Command0_Click()
'now call the function in another control
'for example, find what character position j is at
Call SimilarInstr(Text1, "j")
End Sub
Function SimilarInstr(StrExpression As String, strChar As String) As Integer
Dim i As Integer
For i = 1 To Len(StrExpression) Step 1
If Mid$(StrExpression, i, 1) = strChar Then
SimilarInstr = i
End If
Next i
If SimilarInstr <> 0 Then
MsgBox "Character is at position " & SimilarInstr & " in this expression.", vbSystemModal, "String Position"
Else
MsgBox "Character not found in this string", vbExclamation, "Error"
End If
End Function
'a function that works the same way as the Instr Function does. Comments
No comments yet — be the first to post one!
Post a Comment