VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



'a function that works the same way as the Instr Function does.

by Brandon (46 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 8th January 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

'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.



'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

Download this snippet    Add to My Saved Code

'a function that works the same way as the Instr Function does. Comments

No comments have been posted about 'a function that works the same way as the Instr Function does.. Why not be the first to post a comment about 'a function that works the same way as the Instr Function does..

Post your comment

Subject:
Message:
0/1000 characters