home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- Caption = "Form1"
- ClientHeight = 3525
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 5175
- LinkTopic = "Form1"
- ScaleHeight = 3525
- ScaleWidth = 5175
- StartUpPosition = 3 'Windows Default
- Begin VB.TextBox Text2
- Height = 495
- Left = 1680
- TabIndex = 5
- Text = "ashaMuralidhar"
- Top = 360
- Width = 1815
- End
- Begin VB.CommandButton Command2
- Caption = "Close"
- Height = 495
- Left = 3360
- TabIndex = 4
- Top = 2760
- Width = 1215
- End
- Begin VB.CommandButton Command1
- Caption = "Find"
- Height = 495
- Left = 1800
- TabIndex = 1
- Top = 1800
- Width = 1455
- End
- Begin VB.TextBox Text1
- Height = 495
- Left = 1920
- TabIndex = 0
- Top = 1080
- Width = 1215
- End
- Begin VB.Label Label2
- Caption = "Main String"
- Height = 375
- Left = 600
- TabIndex = 3
- Top = 360
- Width = 1095
- End
- Begin VB.Label Label1
- Caption = "Find string"
- Height = 375
- Left = 720
- TabIndex = 2
- Top = 1080
- Width = 975
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Dim Pos As Integer, temp As String, ctr As Integer
- Private Sub Command1_Click()
- ' Counts the number of occurances of the string
- ctr = 0
- ' gives the position aof the string
- Pos = 0
- If Len(Text1.Text) = 0 Then
- MsgBox "Enter String to be found"
- If Len(Text2.Text) = 0 Then
- MsgBox "Enter String to be searched in"
- temp = Text2.Text ' temporary variable
- ' the loop sees if there are more than one occurance of a string/words in a string
- Pos = InStr(temp, Text1.Text) 'finds the substring in the string
- If Pos = 0 Then ' string not found in main string
- Exit Do
- End If
- ctr = ctr + 1 ' count the number of occurances
- temp = Right(temp, Len(temp) - Pos)
- Loop While (ctr > 0 And Len(temp) > Len(Text1.Text))
- MsgBox ctr ' displays the number of occurances
- End If
- End If
- End Sub
- Private Sub Command2_Click()
- Unload Me
- End Sub
-