home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmMain
- BorderStyle = 1 'Fixed Single
- Caption = "InStrRev"
- ClientHeight = 2085
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 6390
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 2085
- ScaleWidth = 6390
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton cmdGetCharPos
- Caption = "Get Position of String2 in String1"
- Height = 495
- Left = 4920
- TabIndex = 9
- Top = 100
- Width = 1455
- End
- Begin VB.TextBox txtString2
- Height = 285
- Left = 3480
- TabIndex = 5
- Top = 240
- Width = 1335
- End
- Begin VB.Frame frmeString2
- Caption = "String2"
- Height = 615
- Left = 3360
- TabIndex = 4
- Top = 0
- Width = 1575
- End
- Begin VB.TextBox txtString1
- Height = 285
- Left = 840
- TabIndex = 3
- Top = 240
- Width = 2415
- End
- Begin VB.Frame frmString1
- Caption = "String1"
- Height = 615
- Left = 720
- TabIndex = 2
- Top = 0
- Width = 2655
- End
- Begin VB.TextBox txtStart
- Height = 285
- Left = 120
- TabIndex = 1
- Top = 240
- Width = 495
- End
- Begin VB.Frame frmeStart
- Caption = "Start"
- Height = 615
- Left = 0
- TabIndex = 0
- Top = 0
- Width = 735
- End
- Begin VB.Label lblString2Info
- BackStyle = 0 'Transparent
- Caption = "String2 - The string you want to search for."
- Height = 255
- Left = 0
- TabIndex = 8
- Top = 1680
- Width = 6495
- End
- Begin VB.Label lblString1
- BackStyle = 0 'Transparent
- Caption = "String1 - The string that's being searched."
- Height = 255
- Left = 0
- TabIndex = 7
- Top = 1320
- Width = 6255
- End
- Begin VB.Label lblStartInfo
- BackStyle = 0 'Transparent
- Caption = $"frmMain.frx":0000
- Height = 495
- Left = 0
- TabIndex = 6
- Top = 720
- Width = 6375
- End
- Attribute VB_Name = "frmMain"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- '**********************************************************
- '* InStrRev by Joseph Huntley *
- '* joseph_huntley@email.com *
- '* http://joseph.vr9.com *
- '* *
- '* Made: October 1, 1999 *
- '* Level: Beginner *
- '**********************************************************
- '* The form here are only used to demonstrate how to *
- '* use the function 'InStrRev'. You may copy the *
- '* functions into your project for use. If you need any *
- '* help please e-mail me. *
- '**********************************************************
- '* Notes: This function is built into VB6. I wrote this *
- '* function for VB4/VB5 users. *
- '**********************************************************
- Function InStrRev(Optional Start, Optional String1, Optional String2)
- '**********************************************************
- '* InStrRev by Joseph Huntley *
- '* joseph_huntley@email.com *
- '* http://joseph.vr9.com *
- '**********************************************************
- '* You may use this code freely as long as credit is *
- '* given to the author, and the header remains intact. *
- '**********************************************************
- '--------------------- The Arguments -----------------------
- 'Start - The character position to start at. If left blank
- ' the default would be the length of String1
- 'String1 - The string to search.
- 'String2 - The string to search for.
- '-----------------------------------------------------------
- 'Returns: The character position of the first character of
- ' the last instance of String2 before Start.
- 'Description: Searches a string, but in reverse.
- Dim lngLastPos As Long, lngPos As Long, lngStartChar As Long
- Dim strString As String
- 'check to see if String2 is missing. If yes, then
- 'the start argument wasn't given so automatically
- 'give it the value of the length of String1.
- If IsMissing(String2) Then
- lngStartChar& = Len(Start)
- strString$ = CStr(Start)
- strSearchString$ = CStr(String1)
- Else
- lngStartChar& = CLng(Start)
- strString$ = CStr(String1)
- strSearchString$ = CStr(String2)
- End If
- 'if the string can't be found then exit
- If InStr(strString$, strSearchString$) = 0 Then Exit Function
- 'loop through the text until lngPos is bigger than Start or equal to 0.
- 'then return the character position prior to that.
- DoEvents
- lngPos& = InStr(lngLastPos& + 1, strString$, strSearchString$)
- If lngPos& > lngStartChar& Or lngPos& = 0 Then Exit Do
- lngLastPos& = lngPos&
- Loop
- InStrRev = lngLastPos&
- End Function
- Private Sub cmdGetCharPos_Click()
- Dim lngCharPos As Long
- lngCharPos& = InStrRev(txtStart.Text, txtString1.Text, txtString2.Text)
- If lngCharPos& > 0 Then 'if string2 is within string1
- MsgBox "The last instance of String2 starts at character position #" & lngCharPos& & " in String1.", vbInformation
- Else
- MsgBox "String2 is not within String1.", vbInformation
- End If
- End Sub
- Private Sub Form_Load()
- 'set texbox's default values
- txtString1.Text = "InStrRev by Joseph Huntley"
- txtString2.Text = "Joseph"
- txtStart.Text = Len(txtString1.Text)
- End Sub
- Private Sub txtString1_Change()
- 'Set the start position to use the length of String1.
- '(It's automatically default)
- txtStart.Text = Len(txtString1.Text)
- End Sub
-