home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD101909262000.psc / FindWords.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-09-15  |  16.7 KB  |  533 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "WordList by Robert Rayment"
  6.    ClientHeight    =   3195
  7.    ClientLeft      =   165
  8.    ClientTop       =   735
  9.    ClientWidth     =   10305
  10.    BeginProperty Font 
  11.       Name            =   "MS Sans Serif"
  12.       Size            =   12
  13.       Charset         =   0
  14.       Weight          =   700
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    Icon            =   "FindWords.frx":0000
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   213
  22.    ScaleMode       =   3  'Pixel
  23.    ScaleWidth      =   687
  24.    StartUpPosition =   3  'Windows Default
  25.    WindowState     =   2  'Maximized
  26.    Begin VB.Frame Frame1 
  27.       BeginProperty Font 
  28.          Name            =   "MS Sans Serif"
  29.          Size            =   9.75
  30.          Charset         =   0
  31.          Weight          =   700
  32.          Underline       =   0   'False
  33.          Italic          =   0   'False
  34.          Strikethrough   =   0   'False
  35.       EndProperty
  36.       Height          =   1035
  37.       Left            =   720
  38.       TabIndex        =   0
  39.       Top             =   60
  40.       Width           =   10095
  41.       Begin VB.CommandButton Command1 
  42.          Caption         =   "&GO"
  43.          BeginProperty Font 
  44.             Name            =   "MS Sans Serif"
  45.             Size            =   8.25
  46.             Charset         =   0
  47.             Weight          =   400
  48.             Underline       =   0   'False
  49.             Italic          =   0   'False
  50.             Strikethrough   =   0   'False
  51.          EndProperty
  52.          Height          =   510
  53.          Left            =   9420
  54.          TabIndex        =   9
  55.          Top             =   315
  56.          Width           =   555
  57.       End
  58.       Begin VB.TextBox Text1 
  59.          BeginProperty Font 
  60.             Name            =   "MS Sans Serif"
  61.             Size            =   9.75
  62.             Charset         =   0
  63.             Weight          =   400
  64.             Underline       =   0   'False
  65.             Italic          =   0   'False
  66.             Strikethrough   =   0   'False
  67.          EndProperty
  68.          Height          =   345
  69.          Index           =   3
  70.          Left            =   5100
  71.          TabIndex        =   4
  72.          Text            =   "length"
  73.          Top             =   540
  74.          Width           =   1275
  75.       End
  76.       Begin VB.TextBox Text1 
  77.          BeginProperty Font 
  78.             Name            =   "MS Sans Serif"
  79.             Size            =   9.75
  80.             Charset         =   0
  81.             Weight          =   400
  82.             Underline       =   0   'False
  83.             Italic          =   0   'False
  84.             Strikethrough   =   0   'False
  85.          EndProperty
  86.          Height          =   345
  87.          Index           =   2
  88.          Left            =   3480
  89.          TabIndex        =   3
  90.          Text            =   "ending"
  91.          Top             =   540
  92.          Width           =   1275
  93.       End
  94.       Begin VB.TextBox Text1 
  95.          BeginProperty Font 
  96.             Name            =   "MS Sans Serif"
  97.             Size            =   9.75
  98.             Charset         =   0
  99.             Weight          =   400
  100.             Underline       =   0   'False
  101.             Italic          =   0   'False
  102.             Strikethrough   =   0   'False
  103.          EndProperty
  104.          Height          =   345
  105.          Index           =   1
  106.          Left            =   1860
  107.          TabIndex        =   2
  108.          Text            =   "containing"
  109.          Top             =   540
  110.          Width           =   1275
  111.       End
  112.       Begin VB.TextBox Text1 
  113.          BeginProperty Font 
  114.             Name            =   "MS Sans Serif"
  115.             Size            =   9.75
  116.             Charset         =   0
  117.             Weight          =   400
  118.             Underline       =   0   'False
  119.             Italic          =   0   'False
  120.             Strikethrough   =   0   'False
  121.          EndProperty
  122.          Height          =   345
  123.          Index           =   0
  124.          Left            =   240
  125.          TabIndex        =   1
  126.          Text            =   "start"
  127.          Top             =   540
  128.          Width           =   1275
  129.       End
  130.       Begin VB.Label Label2 
  131.          Appearance      =   0  'Flat
  132.          BackColor       =   &H80000004&
  133.          BorderStyle     =   1  'Fixed Single
  134.          Caption         =   $"FindWords.frx":0E42
  135.          BeginProperty Font 
  136.             Name            =   "MS Sans Serif"
  137.             Size            =   8.25
  138.             Charset         =   0
  139.             Weight          =   400
  140.             Underline       =   0   'False
  141.             Italic          =   0   'False
  142.             Strikethrough   =   0   'False
  143.          EndProperty
  144.          ForeColor       =   &H80000008&
  145.          Height          =   795
  146.          Left            =   6540
  147.          TabIndex        =   10
  148.          Top             =   180
  149.          Width           =   2715
  150.       End
  151.       Begin VB.Label Label1 
  152.          Caption         =   "of length"
  153.          BeginProperty Font 
  154.             Name            =   "MS Sans Serif"
  155.             Size            =   9.75
  156.             Charset         =   0
  157.             Weight          =   400
  158.             Underline       =   0   'False
  159.             Italic          =   0   'False
  160.             Strikethrough   =   0   'False
  161.          EndProperty
  162.          Height          =   255
  163.          Index           =   3
  164.          Left            =   5160
  165.          TabIndex        =   8
  166.          Top             =   240
  167.          Width           =   1095
  168.       End
  169.       Begin VB.Label Label1 
  170.          Caption         =   "ending with"
  171.          BeginProperty Font 
  172.             Name            =   "MS Sans Serif"
  173.             Size            =   9.75
  174.             Charset         =   0
  175.             Weight          =   400
  176.             Underline       =   0   'False
  177.             Italic          =   0   'False
  178.             Strikethrough   =   0   'False
  179.          EndProperty
  180.          Height          =   255
  181.          Index           =   2
  182.          Left            =   3540
  183.          TabIndex        =   7
  184.          Top             =   240
  185.          Width           =   1275
  186.       End
  187.       Begin VB.Label Label1 
  188.          Caption         =   "containing"
  189.          BeginProperty Font 
  190.             Name            =   "MS Sans Serif"
  191.             Size            =   9.75
  192.             Charset         =   0
  193.             Weight          =   400
  194.             Underline       =   0   'False
  195.             Italic          =   0   'False
  196.             Strikethrough   =   0   'False
  197.          EndProperty
  198.          Height          =   255
  199.          Index           =   1
  200.          Left            =   1980
  201.          TabIndex        =   6
  202.          Top             =   240
  203.          Width           =   1275
  204.       End
  205.       Begin VB.Label Label1 
  206.          Caption         =   "starting with"
  207.          BeginProperty Font 
  208.             Name            =   "MS Sans Serif"
  209.             Size            =   9.75
  210.             Charset         =   0
  211.             Weight          =   400
  212.             Underline       =   0   'False
  213.             Italic          =   0   'False
  214.             Strikethrough   =   0   'False
  215.          EndProperty
  216.          Height          =   255
  217.          Index           =   0
  218.          Left            =   300
  219.          TabIndex        =   5
  220.          Top             =   240
  221.          Width           =   1275
  222.       End
  223.    End
  224.    Begin VB.Menu brk2 
  225.       Caption         =   "&Dictionary"
  226.       Begin VB.Menu ProperNames 
  227.          Caption         =   "&Proper Names"
  228.       End
  229.       Begin VB.Menu UKACD 
  230.          Caption         =   "&UKACD"
  231.       End
  232.       Begin VB.Menu brk1 
  233.          Caption         =   "-"
  234.       End
  235.       Begin VB.Menu ExitProg 
  236.          Caption         =   "E&xit"
  237.       End
  238.    End
  239. Attribute VB_Name = "Form1"
  240. Attribute VB_GlobalNameSpace = False
  241. Attribute VB_Creatable = False
  242. Attribute VB_PredeclaredId = True
  243. Attribute VB_Exposed = False
  244. 'FindWords by Robert Rayment
  245. 'Dictionaries
  246. 'UKACD lower case extracted & proper names extracted
  247. 'Both modified to remove phrases, accented letters,
  248. 'apostrophes etc.
  249. 'Source:-
  250. 'The UKACD dictionary is copyrighted but freeware
  251. 'see UKACD.txt in the Apps folder
  252. Option Base 1
  253. Dim WordData() As Byte
  254. Dim ALB&()  'Alphabet start binary positions
  255. Dim FileIn$, FSize&
  256. Dim NumOfWords&, maxlen, WordCount, wpntr&
  257. Dim serstart$, ser$, serend$, sertyp, wordlen$, lenlim, lenop
  258. Private Sub Form_Load()
  259. Form1.Caption = "FindWords by Robert Rayment  " + Str$(Now)
  260. Refresh
  261. MousePointer = 11
  262. 'Start dictionary "ACDLC0A.txt"
  263. UKACD_Click
  264. 'FileIn$ = "ACDLC0A.txt"
  265. 'OpenDictionary 'FileIn$
  266. MousePointer = 0
  267. End Sub
  268. Private Sub Command1_Click()
  269. 'Global NumOfWords&, maxlen, WordCount, wpntr&
  270. 'Global serstart$, ser$, serend$, lenlim, sertyp
  271. ' text  0          1     2        3
  272. 'sertyp 2          4     8
  273. '2, 4, 8
  274. '6(2+4), 10(2+8), 12(4+8), 14(2+4+8)
  275. Form1.Cls
  276. Refresh
  277. SubWordCount = 0
  278. Form1.CurrentY = 80
  279. Form1.MousePointer = 11
  280. sertyp = 0
  281. Firstletter$ = ""
  282. If serstart$ <> "" Then
  283.    serstart$ = LCase(serstart$)
  284.    If FileIn$ = "ProperNames.txt" Then
  285.       a$ = UCase$(Left$(serstart$, 1))
  286.       Mid$(serstart$, 1, 1) = a$
  287.    End If
  288.    sertyp = 2
  289.    Firstletter$ = Left$(serstart$, 1)
  290. End If
  291. If ser$ <> "" Then sertyp = sertyp + 4: ser$ = LCase(ser$)
  292. If serend$ <> "" Then sertyp = sertyp + 8: serend$ = LCase(serend$):
  293. lenwordbits = Len(serstart$) + Len(ser$) + Len(serend$)
  294. Find_lenlim_lenop
  295. If lenwordbits = 0 And lenlim = 0 Then Form1.MousePointer = 0: Beep: Exit Sub
  296. If lenwordbits = 0 And lenlim > 0 Then sertyp = 16
  297. 'Set search to start letter
  298. If wpntr& = 1 Then
  299.    If Left(serstart$, 1) <> "" Then
  300.       a$ = Left(serstart$, 1)
  301.       n = Asc(a$) - 96
  302.       If n >= 1 And n <= 26 Then wpntr& = ALB&(n)
  303.    End If
  304. End If
  305.    Word$ = ""
  306.    For i& = wpntr& To wpntr& + 50
  307.       If i& >= FSize& Then Exit Do
  308.       If WordData(i&) = &HA Then p2& = i&: Exit For
  309.    Next i&
  310.    For j& = wpntr& To p2& - 1
  311.       Word$ = Word$ + Chr$(WordData(j&))
  312.    Next j&
  313.    If Firstletter$ <> "" And Left$(Word$, 1) > Firstletter$ Then Exit Do
  314.    lenword = Len(Word$)
  315.    wpntr& = p2& + 1  'For next word
  316.    Form1.CurrentX = 50
  317.    If SubWordCount >= 22 Then Form1.CurrentX = 50 + 170
  318.    If SubWordCount >= 44 Then Form1.CurrentX = 50 + 170 + 170
  319.    If SubWordCount >= 66 Then Form1.CurrentX = 50 + 170 + 170 + 170
  320.    If lenword < lenwordbits And sertyp <> 16 Then GoTo nextloop
  321.    matchtest = False
  322.    Select Case sertyp
  323.    Case 2 'Words starting with serstart$
  324.       m1 = InStr(1, Word$, serstart$)
  325.       If m1 = 1 Then matchtest = True
  326.    Case 4   'Words containing ser$
  327.       m1 = InStr(1, Word$, ser$)
  328.       If m1 <> 0 Then matchtest = True
  329.    Case 6   'Words starting with serstart$ and containing ser$
  330.       m1 = InStr(1, Word$, serstart$)
  331.       If m1 = 1 Then
  332.          m2 = InStr(m1 + 1, Word$, ser$)
  333.          If m2 <> 0 Then matchtest = True
  334.       End If
  335.    Case 8   'Words ending in serend$
  336.       m1 = InStr(1, Word$, serend$)
  337.       If m1 <> 0 And m1 = lenword - Len(serend$) + 1 Then matchtest = True
  338.    Case 10   'Words starting with serstart$ and ending in serend$
  339.       m1 = InStr(1, Word$, serstart$)
  340.       If m1 = 1 Then
  341.          m2 = InStr(m1 + 1, Word$, serend$)
  342.          If m2 <> 0 And m2 = lenword - Len(serend$) + 1 Then matchtest = True
  343.       End If
  344.    Case 12   'Words containing ser$ and ending in serend$
  345.       m1 = InStr(1, Word$, ser$)
  346.       If m1 <> 0 Then
  347.          m2 = InStr(m1 + 1, Word$, serend$)
  348.          If m2 <> 0 And m2 = lenword - Len(serend$) + 1 Then matchtest = True
  349.       End If
  350.    Case 14   'Words starting with serstart$, containing ser$ and ending in serend$
  351.       m1 = InStr(1, Word$, serstart$)
  352.       If m1 = 1 Then
  353.          m2 = InStr(m1 + 1, Word$, ser$)
  354.          If m2 <> 0 Then
  355.             m3 = InStr(m2 + 1, Word$, serend$)
  356.             If m3 <> 0 And m3 = lenword - Len(serend$) + 1 Then matchtest = True
  357.          End If
  358.       End If
  359.    Case 16  'all words of length=lenlim
  360.       matchtest = True
  361.    End Select
  362.    If matchtest Then
  363.       match = False
  364.       Select Case lenop
  365.       Case 0: If lenword = lenlim Or lenlim = 0 Then match = True
  366.       Case 1: If lenword < lenlim Then match = True
  367.       Case 2: If lenword <= lenlim Then match = True
  368.       Case 3: If lenword > lenlim Then match = True
  369.       Case 4: If lenword >= lenlim Then match = True
  370.       End Select
  371.       If match Then
  372.          WordCount = WordCount + 1: SubWordCount = SubWordCount + 1: Form1.Print Word$
  373.          If SubWordCount > 87 Then Exit Do
  374.          If SubWordCount = 22 Then Form1.CurrentY = 80
  375.          If SubWordCount = 44 Then Form1.CurrentY = 80
  376.          If SubWordCount = 66 Then Form1.CurrentY = 80
  377.       End If
  378.    End If
  379. nextloop:
  380.    If wpntr& >= FSize& Then Exit Do
  381. Form1.MousePointer = 0
  382. Form1.CurrentX = 50
  383. Form1.CurrentY = 525
  384. If SubWordCount = 88 Then
  385.    Form1.Print WordCount; " words found.  GO for more"
  386.    Form1.Print WordCount; " words found"
  387. End If
  388. Form1.Refresh
  389. If SubWordCount = 0 Then
  390.    WordCount = 0
  391.    wpntr& = 1
  392. End If
  393. End Sub
  394. Private Sub Find_lenlim_lenop()
  395. 'Global wordlen$,lenlim,lenop
  396. lenlim = 0
  397. lenop = 0   '0=   1<   2<=  3>  4>=
  398. If wordlen$ <> "" Then
  399.     lef1$ = Left$(wordlen$, 1)
  400.     If lef1$ >= "1" And lef1$ <= "9" Then 'Number only
  401.         lenlim = Val(wordlen$)
  402.         Exit Sub
  403.     End If
  404.     lef2$ = Mid$(wordlen$, 2, 1)
  405.     Select Case lef1$
  406.     Case "="
  407.         lenlim = Val(Mid$(wordlen$, 2))
  408.     Case "<"
  409.         If lef2$ <> "=" Then
  410.             lenlim = Val(Mid$(wordlen$, 2))
  411.             lenop = 1
  412.         Else
  413.             lenlim = Val(Mid$(wordlen$, 3))
  414.             lenop = 2
  415.         End If
  416.     Case ">"
  417.         If lef2$ <> "=" Then
  418.             lenlim = Val(Mid$(wordlen$, 2))
  419.             lenop = 3
  420.         Else
  421.             lenlim = Val(Mid$(wordlen$, 3))
  422.             lenop = 4
  423.         End If
  424.     End Select
  425. End If
  426. End Sub
  427. Private Sub Text1_Change(Index As Integer)
  428. 'Comes here as each character pressed
  429. Select Case Index
  430. Case 0: serstart$ = Text1(Index).Text
  431. Case 1: ser$ = Text1(Index).Text
  432. Case 2: serend$ = Text1(Index).Text
  433. Case 3: wordlen$ = Text1(Index).Text
  434. End Select
  435. WordCount = 0
  436. wpntr& = 1
  437. End Sub
  438. Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
  439. If KeyAscii = 27 Then Exit Sub
  440. If KeyAscii = 13 Then
  441.    KeyAscii = 0
  442.    Select Case Index
  443.    Case 0: serstart$ = Trim$(Text1(0).Text)
  444.    Case 1: ser$ = Trim$(Text1(1).Text)
  445.    Case 2: serend$ = Trim$(Text1(2).Text)
  446.    Case 3: a$ = Trim$(Text1(Index).Text)
  447.       lenlim = 0
  448.       lenop = 0 '0=   1<   2<=
  449.       If a$ <> "" Then
  450.         op$ = Left(a$, 1)
  451.         If op$ = "<" Then
  452.            lenop = 1
  453.            a$ = Mid$(a$, 2)
  454.            If op$ = "=" Then
  455.               lenop = 2
  456.               a$ = Mid$(a$, 2)
  457.             End If
  458.         ElseIf op$ = "=" Then
  459.            lenop = 0
  460.            a$ = Mid$(a$, 2)
  461.         End If
  462.         lenlim = Val(a$)
  463.       End If
  464.    End Select
  465.    WordCount = 0
  466.    wpntr& = 1
  467. End If
  468. End Sub
  469. Private Sub UKACD_Click()
  470. Frame1.Caption = "Find words from 173099 words in UKACD's Dictionary"
  471. 'UKACD Lower Case, words terminated by 0Ah
  472. FileIn$ = "ACDLC0A.txt"
  473. OpenDictionary 'FileIn$
  474. End Sub
  475. Private Sub ProperNames_Click()
  476. Frame1.Caption = "Find words from 24256 Proper Names"
  477. FileIn$ = "ProperNames.txt"
  478. OpenDictionary 'FileIn$
  479. End Sub
  480. Private Sub OpenDictionary()
  481. 'Global WordData() As Byte
  482. 'Global ALB&()  'Alphabet start binary positions
  483. 'Global FileIn$, FSize&
  484. 'Global NumOfWords&, maxlen, WordCount, wpntr&
  485. Form1.Cls
  486. Refresh
  487. NumOfWords& = 0&
  488. maxlen = 0
  489. Open FileIn$ For Binary As #1
  490. FSize& = LOF(1)
  491. ReDim WordData(FSize&)
  492. Get #1, , WordData
  493. Close
  494. 'NB Words are separated by &HA
  495. 'Set ALB&() pointer to the start of each alphabetic group
  496. ReDim ALB&(1 To 26)
  497. ALB&(1) = 1 'Pointer to 'a'
  498. ab = 97    'a
  499. ai = 1
  500. ab = 98    'b
  501. ai = 2
  502. For n& = 1 To FSize& - 1
  503.     If WordData(n&) = &HA Then 'separator after end of word
  504.        If WordData(n& + 1) = ab Then
  505.           ALB&(ai) = n& + 1
  506.           ab = ab + 1
  507.           ai = ai + 1
  508.        End If
  509.     End If
  510. Next n&
  511. 'Global serstart$, ser$, serend$, lenlim, sertyp
  512. For i = 0 To 3
  513. Text1(i) = ""
  514. Next i
  515. 'Global NumOfWords&, maxlen, WordCount, wpntr&
  516. WordCount = 0
  517. wpntr& = 1
  518. serstart$ = ""
  519. ser$ = ""
  520. serend$ = ""
  521. lenlim = 0
  522. lenop = 0 '0=   1<   2<=
  523. Text1(0) = serstart$
  524. Text1(1) = ser$
  525. Text1(2) = serend$
  526. Text1(3) = ""
  527. sertyp = 0
  528. DoEvents
  529. End Sub
  530. Private Sub ExitProg_Click()
  531. Unload Me
  532. End Sub
  533.