home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Fast_Sub-S2169531272009.psc / SubStrCount / SubStrCnt.frm < prev    next >
Text File  |  2009-11-28  |  11KB  |  347 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSubStrCnt 
  3.    Caption         =   "Sub-String Count Ex"
  4.    ClientHeight    =   5220
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4335
  8.    LinkTopic       =   "Form1"
  9.    LockControls    =   -1  'True
  10.    ScaleHeight     =   5220
  11.    ScaleWidth      =   4335
  12.    StartUpPosition =   2  'CenterScreen
  13.    Begin VB.CommandButton cmdTest 
  14.       Caption         =   "Performance Test..."
  15.       Height          =   345
  16.       Left            =   180
  17.       TabIndex        =   12
  18.       Top             =   3300
  19.       Width           =   1725
  20.    End
  21.    Begin VB.TextBox txtStart 
  22.       Height          =   285
  23.       Left            =   1140
  24.       TabIndex        =   10
  25.       Top             =   2850
  26.       Width           =   555
  27.    End
  28.    Begin VB.TextBox txtLimit 
  29.       Height          =   285
  30.       Left            =   3330
  31.       TabIndex        =   8
  32.       Top             =   2850
  33.       Width           =   465
  34.    End
  35.    Begin VB.TextBox txtHits 
  36.       Height          =   255
  37.       Left            =   3300
  38.       TabIndex        =   6
  39.       Top             =   2370
  40.       Width           =   465
  41.    End
  42.    Begin VB.CheckBox chkWWonly 
  43.       Caption         =   "Whole Words Only"
  44.       Height          =   255
  45.       Left            =   420
  46.       TabIndex        =   4
  47.       Top             =   2520
  48.       Width           =   2055
  49.    End
  50.    Begin VB.CheckBox chkCaseSens 
  51.       Caption         =   "Case Sensitive"
  52.       Height          =   195
  53.       Left            =   570
  54.       TabIndex        =   3
  55.       Top             =   2220
  56.       Width           =   1695
  57.    End
  58.    Begin VB.CommandButton cmdCount 
  59.       Caption         =   "Count Now..."
  60.       Height          =   345
  61.       Left            =   2850
  62.       TabIndex        =   2
  63.       Top             =   1830
  64.       Width           =   1155
  65.    End
  66.    Begin VB.TextBox txtSubText 
  67.       Height          =   315
  68.       Left            =   1710
  69.       TabIndex        =   1
  70.       Top             =   1830
  71.       Width           =   1005
  72.    End
  73.    Begin VB.TextBox txtSearchText 
  74.       Height          =   1395
  75.       HideSelection   =   0   'False
  76.       Left            =   330
  77.       MultiLine       =   -1  'True
  78.       ScrollBars      =   2  'Vertical
  79.       TabIndex        =   0
  80.       Top             =   210
  81.       Width           =   3675
  82.    End
  83.    Begin VB.Label Label5 
  84.       Caption         =   "mInStrCnt.InStrCount04:"
  85.       Height          =   210
  86.       Index           =   3
  87.       Left            =   210
  88.       TabIndex        =   22
  89.       Top             =   4290
  90.       Width           =   2205
  91.    End
  92.    Begin VB.Label Label5 
  93.       Height          =   210
  94.       Index           =   8
  95.       Left            =   2520
  96.       TabIndex        =   21
  97.       Top             =   4290
  98.       Width           =   2205
  99.    End
  100.    Begin VB.Label Label5 
  101.       Height          =   210
  102.       Index           =   10
  103.       Left            =   2520
  104.       TabIndex        =   20
  105.       Top             =   4830
  106.       Width           =   1965
  107.    End
  108.    Begin VB.Label Label5 
  109.       Height          =   210
  110.       Index           =   9
  111.       Left            =   2520
  112.       TabIndex        =   19
  113.       Top             =   4560
  114.       Width           =   2025
  115.    End
  116.    Begin VB.Label Label5 
  117.       Height          =   210
  118.       Index           =   7
  119.       Left            =   2520
  120.       TabIndex        =   18
  121.       Top             =   4020
  122.       Width           =   2205
  123.    End
  124.    Begin VB.Label Label5 
  125.       Height          =   210
  126.       Index           =   6
  127.       Left            =   2520
  128.       TabIndex        =   17
  129.       Top             =   3750
  130.       Width           =   2205
  131.    End
  132.    Begin VB.Label Label5 
  133.       Caption         =   "Your InStrCnt:"
  134.       Height          =   210
  135.       Index           =   5
  136.       Left            =   720
  137.       TabIndex        =   16
  138.       Top             =   4830
  139.       Width           =   1695
  140.    End
  141.    Begin VB.Label Label5 
  142.       Caption         =   "mInStrCnt.InStrCnt:"
  143.       Height          =   210
  144.       Index           =   4
  145.       Left            =   480
  146.       TabIndex        =   15
  147.       Top             =   4560
  148.       Width           =   2025
  149.    End
  150.    Begin VB.Label Label5 
  151.       Caption         =   "mSubStrCnt.SubStringCount:"
  152.       Height          =   210
  153.       Index           =   2
  154.       Left            =   180
  155.       TabIndex        =   14
  156.       Top             =   4020
  157.       Width           =   2205
  158.    End
  159.    Begin VB.Label Label5 
  160.       Caption         =   "mSubStrCnt.SubStrCount:"
  161.       Height          =   210
  162.       Index           =   1
  163.       Left            =   390
  164.       TabIndex        =   13
  165.       Top             =   3750
  166.       Width           =   2205
  167.    End
  168.    Begin VB.Label Label4 
  169.       Caption         =   "Start At:"
  170.       Height          =   285
  171.       Left            =   420
  172.       TabIndex        =   11
  173.       Top             =   2880
  174.       Width           =   1065
  175.    End
  176.    Begin VB.Label Label3 
  177.       Caption         =   "Limit Hit Count To:"
  178.       Height          =   225
  179.       Left            =   1890
  180.       TabIndex        =   9
  181.       Top             =   2880
  182.       Width           =   2085
  183.    End
  184.    Begin VB.Label Label2 
  185.       Caption         =   "Hits:"
  186.       Height          =   195
  187.       Left            =   2850
  188.       TabIndex        =   7
  189.       Top             =   2400
  190.       Width           =   765
  191.    End
  192.    Begin VB.Label Label1 
  193.       Caption         =   "Search Sub-String:"
  194.       Height          =   225
  195.       Left            =   300
  196.       TabIndex        =   5
  197.       Top             =   1860
  198.       Width           =   2115
  199.    End
  200. End
  201. Attribute VB_Name = "frmSubStrCnt"
  202. Attribute VB_GlobalNameSpace = False
  203. Attribute VB_Creatable = False
  204. Attribute VB_PredeclaredId = True
  205. Attribute VB_Exposed = False
  206. Option Explicit
  207.  
  208. Private Declare Function PerfCount Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As Currency) As Long
  209. Private Declare Function PerfFreq Lib "kernel32" Alias "QueryPerformanceFrequency" (lpFrequency As Currency) As Long
  210. Private mCurFreq As Currency
  211.  
  212. Private lStart As Long
  213.  
  214. Private Function ProfileStart() As Currency
  215.     If mCurFreq = 0 Then PerfFreq mCurFreq
  216.     If (mCurFreq) Then PerfCount ProfileStart
  217. End Function
  218.  
  219. Private Function ProfileStop(ByVal curStart As Currency) As Currency
  220.     If (mCurFreq) Then
  221.         Dim curStop As Currency
  222.         PerfCount curStop
  223.         ProfileStop = (curStop - curStart) / mCurFreq ' cpu tick accurate
  224.         curStop = 0
  225.     End If
  226. End Function
  227.  
  228. Private Function OpenFile(sFileSpec As String) As String
  229.     ' Handle errors if they occur
  230.     On Error GoTo GetFileError
  231.     Dim iFile As Integer
  232.     iFile = FreeFile
  233.     ' Open in binary mode, let others read but not write
  234.     Open sFileSpec For Binary Access Read Lock Write As #iFile
  235.     ' Allocate the length first
  236.     OpenFile = Space$(LOF(iFile))
  237.     ' Get the file in one chunk
  238.     Get #iFile, , OpenFile
  239. GetFileError:
  240.     Close #iFile ' Close the file
  241. End Function
  242.  
  243. Private Sub cmdTest_Click()
  244.     Dim curElapse As Currency
  245.     Dim sFile As String
  246.     Dim r1 As Single
  247.     Dim i As Long
  248.  
  249.     For i = 6 To 10
  250.         Label5(i) = vbNullString
  251.         Label5(i).Refresh
  252.     Next i
  253.  
  254.     Screen.MousePointer = vbHourglass
  255.     sFile = OpenFile(App.Path & "\SubStrCnt.bas")
  256.  
  257.     curElapse = ProfileStart
  258.     For i = 1 To 10000
  259.         txtHits = SubStrCount(sFile, "is", 1, Abs(chkCaseSens - 1), CBool(chkWWonly))
  260.     Next i
  261.     r1 = CSng(ProfileStop(curElapse))
  262.     Label5(6) = Format$(r1, "##0.0000") & " secs"
  263.     Label5(6).Refresh
  264.     
  265.     curElapse = ProfileStart
  266.     For i = 1 To 10000
  267.         txtHits = SubStringCount(sFile, "is", 1, Abs(chkCaseSens - 1), CBool(chkWWonly))
  268.     Next i
  269.     r1 = CSng(ProfileStop(curElapse))
  270.     Label5(7) = Format$(r1, "##0.0000") & " secs"
  271.     Label5(7).Refresh
  272.  
  273.     If chkWWonly = 0 Then
  274.  
  275.         curElapse = ProfileStart
  276.         For i = 1 To 10000
  277.             txtHits = InStrCount04(sFile, "is", 1, Abs(chkCaseSens - 1))
  278.         Next i
  279.         r1 = CSng(ProfileStop(curElapse))
  280.         Label5(8) = Format$(r1, "##0.0000") & " secs"
  281.         Label5(8).Refresh
  282.  
  283.         curElapse = ProfileStart
  284.         For i = 1 To 10000
  285.             txtHits = InStrCnt(sFile, "is", 1, CBool(chkCaseSens))
  286.         Next i
  287.         r1 = CSng(ProfileStop(curElapse))
  288.         Label5(9) = Format$(r1, "##0.0000") & " secs"
  289.         Label5(9).Refresh
  290.  
  291.     Else
  292.         Label5(8) = "999999"
  293.         Label5(8).Refresh
  294.         Label5(9) = "999999"
  295.         Label5(9).Refresh
  296.     End If
  297.     
  298. '    curElapse = ProfileStart
  299. '    For i = 1 To 10000 'YourInStrCnt
  300. '        txtHits = YourInStrCnt(sFile, "is", 1, Abs(chkCaseSens - 1), CBool(chkWWonly))
  301. '    Next i
  302. '    r1 = CSng(ProfileStop(curElapse))
  303. '    Label5(10) = Format$(r1, "##0.0000") & " secs"
  304. '    Label5(10).Refresh
  305.  
  306.     Screen.MousePointer = vbDefault
  307. End Sub
  308.  
  309. Private Sub Form_Load()
  310.   txtSearchText = "This is the Search Text2search for occurences of text sub-strings that may be searched in this search text. This search Text is only 278Text characters in the txtSearchText text Control. I hope this Search_text will help you with your Text context searching research."
  311.   txtSubText = "Text"
  312.   txtStart = "1"
  313.   txtLimit = "1"
  314. End Sub
  315.  
  316. Private Sub cmdCount_Click()
  317. 'count now
  318.   txtSearchText.SelLength = 0
  319.   lStart = txtStart
  320.   'txtHits = SubStrCount(txtSearchText, txtSubText, lStart, Abs(chkCaseSens - 1), CBool(chkWWonly), txtLimit)
  321.   txtHits = SubStringCount(txtSearchText, txtSubText, lStart, Abs(chkCaseSens - 1), CBool(chkWWonly), txtLimit)
  322.  
  323.   If txtLimit > 0 And lStart > 0 Then
  324.       txtSearchText.SelStart = lStart - 1 ' zero based sel
  325.       txtSearchText.SelLength = Len(txtSubText)
  326.       txtStart = lStart + 1
  327.   Else
  328.       txtStart = "0"
  329.   End If
  330. End Sub
  331.  
  332. Private Sub txtSearchText_Click()
  333.     txtStart = txtSearchText.SelStart + 1 ' zero based sel
  334. End Sub
  335.  
  336. Private Sub txtSearchText_KeyUp(KeyCode As Integer, Shift As Integer)
  337.     If (txtSearchText.SelLength > 0) Then
  338.         txtSubText = Trim$(txtSearchText.SelText)
  339.     End If
  340. End Sub
  341.  
  342. Private Sub txtSearchText_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  343.     If (txtSearchText.SelLength > 0) Then
  344.         txtSubText = Trim$(txtSearchText.SelText)
  345.     End If
  346. End Sub
  347.