home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 November / pcwk_11_98a.iso / Wtestowe / SOFTSRC / vtrial15.exe / DATA.1 / SpellChk.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-03-21  |  6.6 KB  |  197 lines

  1. VERSION 4.00
  2. Begin VB.Form SpellChk 
  3.    Caption         =   "Spelling Checker Example"
  4.    ClientHeight    =   1575
  5.    ClientLeft      =   1170
  6.    ClientTop       =   1515
  7.    ClientWidth     =   4455
  8.    Height          =   1980
  9.    Icon            =   "SpellChk.frx":0000
  10.    Left            =   1110
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   1575
  13.    ScaleWidth      =   4455
  14.    Top             =   1170
  15.    Width           =   4575
  16.    Begin VB.CheckBox CheckZoomText 
  17.       Caption         =   "&Zoom to Text"
  18.       Enabled         =   0   'False
  19.       Height          =   255
  20.       Left            =   2040
  21.       TabIndex        =   5
  22.       Top             =   960
  23.       Width           =   2295
  24.    End
  25.    Begin VB.CommandButton Complete 
  26.       Caption         =   "&Done"
  27.       Height          =   375
  28.       Left            =   240
  29.       TabIndex        =   2
  30.       Top             =   1080
  31.       Width           =   1455
  32.    End
  33.    Begin VB.CheckBox CheckNumbers 
  34.       Caption         =   "Ignore Words with &Numbers"
  35.       Enabled         =   0   'False
  36.       Height          =   255
  37.       Left            =   2040
  38.       TabIndex        =   3
  39.       Top             =   240
  40.       Width           =   2295
  41.    End
  42.    Begin VB.CheckBox CheckUppercase 
  43.       Caption         =   "Ignore &UPPERCASE words"
  44.       Enabled         =   0   'False
  45.       Height          =   255
  46.       Left            =   2040
  47.       TabIndex        =   4
  48.       Top             =   600
  49.       Width           =   2295
  50.    End
  51.    Begin VB.CommandButton PickObject 
  52.       Caption         =   "&Pick Object"
  53.       Height          =   375
  54.       Left            =   240
  55.       TabIndex        =   0
  56.       Top             =   120
  57.       Width           =   1455
  58.    End
  59.    Begin VB.CommandButton EntireDrawing 
  60.       Caption         =   "&Entire Drawing"
  61.       Height          =   375
  62.       Left            =   240
  63.       TabIndex        =   1
  64.       Top             =   600
  65.       Width           =   1455
  66.    End
  67.    Begin VeventsLib.VdraftEvents VdraftEvents1 
  68.       Left            =   3480
  69.       Top             =   1080
  70.       _Version        =   65536
  71.       _ExtentX        =   1508
  72.       _ExtentY        =   661
  73.       _StockProps     =   0
  74.    End
  75. Attribute VB_Name = "SpellChk"
  76. Attribute VB_Creatable = False
  77. Attribute VB_Exposed = False
  78. Dim WordObj As Object
  79. Dim Temporary_WindowName$
  80. Private Function SpellCheckString(ByRef old$) As Boolean
  81.     Dim str$
  82.     WordObj.AppShow
  83.     WordObj.EditSelectAll           ' select everything
  84.     WordObj.EditClear 2             ' out with the old
  85.     WordObj.Insert old$             ' in with the new
  86.     On Error Resume Next            ' errors even when success!?!
  87.     WordObj.ToolsSpelling           ' spell check it
  88.     WordObj.EditSelectAll           ' select everything
  89.     str$ = WordObj.Selection$()     ' grab the new text
  90.     str$ = Left$(str$, Len(str$) - 1)
  91.     AppActivate "Virtual Drafter -"
  92.     If old$ = str$ Then
  93.         SpellCheckString = False    ' text is the same
  94.     Else
  95.         SpellCheckString = True     ' text is different
  96.         old$ = str$                 ' return new text
  97.     End If
  98. End Function
  99. Private Sub SpellCheckEntity(Entity As Object)
  100.     Dim str$, Count%
  101.     ' determine if entity suitable for spell check and aquire text
  102.     If Entity.Type = veET_Text Or Entity.Type = veET_Attdef Then
  103.         str$ = Entity.Text
  104.         If SpellCheckString(str$) Then
  105.             Entity.Text = str$
  106.         End If
  107.     ElseIf Entity.Type = veET_Insert Then
  108.         If Entity.HasAttributes Then
  109.             Dim Attributes, Attrib As Object
  110.             Set Attributes = Entity.Attributes
  111.             For Count% = 1 To Attributes.Count
  112.                 Set Attrib = Attributes(Count)
  113.                 str$ = Attrib.Text
  114.                 If SpellCheckString(str$) Then Attrib.Text = str$
  115.             Next
  116.         End If
  117.     End If
  118. End Sub
  119. Private Sub Complete_Click()
  120.     Form_Unload False
  121.     End
  122. End Sub
  123. Private Sub EntireDrawing_Click()
  124.     Dim Entities, Entity As Object
  125.     Dim Count As Long
  126.     ' connect to vdraft
  127.     If VdraftEvents1.Connect = False Then
  128.         MsgBox "Could not connect with Vdraft"
  129.         Exit Sub
  130.     End If
  131.     ' make sure that at least one document is available
  132.     If VdraftEvents1.vdraft.Documents.Count = 0 Then
  133.         MsgBox "No drawings currently loaded."
  134.         Exit Sub
  135.     End If
  136.     ' get a handle on the active document
  137.     Set Entities = VdraftEvents1.vdraft.ActiveDocument.Entities
  138.     For Count = 1 To Entities.Count
  139.         Set Entity = Entities(Count)
  140.         SpellCheckEntity Entity
  141.     Next
  142. End Sub
  143. Private Sub Form_Load()
  144.     On Error Resume Next
  145.     ' try and get hold of existing one
  146.     Set WordObj = GetObject("Word.Basic")
  147.     If WordObj Is Nothing Then
  148.         ' try and create one
  149.         Set WordObj = CreateObject("Word.Basic")
  150.     End If
  151.     If WordObj Is Nothing Then
  152.         MsgBox "Unable to establish connection with Microsoft Word"
  153.         Exit Sub
  154.     End If
  155.     ' create a temporary document that we can work with
  156.     WordObj.FileNew
  157.     Temporary_WindowName$ = WordObj.WindowName$()
  158. End Sub
  159. Private Sub Form_Unload(Cancel As Integer)
  160.     If Not (WordObj Is Nothing) Then
  161.         ' close down our temporary file
  162.         WordObj.Activate Temporary_WindowName$
  163.         WordObj.DocClose 2
  164.     End If
  165.     Set WordObj = Nothing
  166.     VdraftEvents1.Disconnect
  167. End Sub
  168. Private Sub PickObject_Click()
  169.     ' connect to vdraft
  170.     If VdraftEvents1.Connect = False Then
  171.         MsgBox "Could not connect with Vdraft"
  172.         Exit Sub
  173.     End If
  174.     ' make sure that at least one document is available
  175.     If VdraftEvents1.vdraft.Documents.Count = 0 Then
  176.         MsgBox "No drawings currently loaded."
  177.         Exit Sub
  178.     End If
  179.     ' get a handle on the active document
  180.     Set SelectEvents = VdraftEvents1.vdraft.ActiveDocument.SelectionEvents
  181.     SelectEvents.statusbar = "Select text object to spell check"
  182.     SelectEvents.Name = "to spell check"
  183.     ' we want to know when the user has selected an object
  184.     VdraftEvents1.RequestSingleSelect SelectEvents, 0
  185. End Sub
  186. Private Sub VdraftEvents1_SelectDone(ByVal info As Long)
  187.     Dim Selection As Object
  188.     Set Selection = VdraftEvents1.vdraft.ActiveDocument.Selection
  189.     ' try to spell check the first entity in the selection
  190.     ' set, if it can not be checked let the user try again
  191.     If Selection.HasItems Then
  192.         SpellCheckEntity Selection(1)
  193.         Selection.RemoveAll
  194.     End If
  195.     PickObject_Click  ' have them pick again
  196. End Sub
  197.