home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form frmTalk
- Caption = "OLE Automation Talker"
- ClientHeight = 3570
- ClientLeft = 1095
- ClientTop = 1500
- ClientWidth = 7395
- Height = 3975
- Icon = "frmtalk.frx":0000
- Left = 1035
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 3570
- ScaleWidth = 7395
- Top = 1155
- Width = 7515
- Begin VB.CommandButton cmd
- Caption = "Replace Every Occurrence of a Word in Text Server with a New Word"
- Height = 375
- Index = 2
- Left = 135
- TabIndex = 3
- Top = 3105
- Width = 7125
- End
- Begin VB.CommandButton cmd
- Caption = "Get Text from Text Server"
- Height = 375
- Index = 1
- Left = 135
- TabIndex = 2
- Top = 2655
- Width = 7125
- End
- Begin VB.TextBox Text1
- BeginProperty Font
- name = "Courier New"
- charset = 0
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 1995
- Left = 135
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 0
- Text = "frmtalk.frx":030A
- Top = 135
- Width = 7125
- End
- Begin VB.CommandButton cmd
- Caption = "Send Text to Text Server"
- Height = 375
- Index = 0
- Left = 135
- TabIndex = 1
- Top = 2205
- Width = 7125
- End
- Attribute VB_Name = "frmTalk"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- '*********************************************************************
- ' Create a object that won't go out of scope too early.
- '*********************************************************************
- Option Explicit
- Private TextServer As Object
- '*********************************************************************
- ' Process command button clicks.
- '*********************************************************************
- Private Sub cmd_Click(Index As Integer)
- Dim FindText$, ReplaceWith$
- Select Case Index
- Case 0 'Send Text to Text Server
- '*********************************************************
- ' SetEditText takes 1 argument (a string). TextServer
- ' uses this string to populate its text box.
- '*********************************************************
- TextServer.SetEditText Text1
- TextServer.Show
- Case 1 'Get Text from Text Server
- '*********************************************************
- ' GetEditText returns a string that contains the contents
- ' of TextServer's text box.
- '*********************************************************
- Text1 = TextServer.GetEditText()
- Case 2 'Get Text from Text Server
- '*********************************************************
- ' ReplaceAll finds every occurance of a word, and replaces
- ' it with a new word. After the replace is complete, the
- ' TextServer text box is updated to reflect the changes.
- '*********************************************************
- FindText = InputBox("Find What?")
- If FindText = "" Then Exit Sub
- ReplaceWith = InputBox("Replace With?")
- If FindText = "" Then Exit Sub
- TextServer.ReplaceAll FindText, ReplaceWith
- TextServer.Show
- End Select
-
- End Sub
- '*********************************************************************
- ' Loads the form and establishes a connection with TextServer.
- '*********************************************************************
- Private Sub Form_Load()
- On Error Resume Next
- Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
- '*****************************************************************
- ' As a precaution, it useful to always register your server first.
- '*****************************************************************
- RegisterTextServer
- '*****************************************************************
- ' As this line demonstrates, all objects are created the same way.
- '*****************************************************************
- Set TextServer = CreateObject("Text.Document")
- LoadText
- '*****************************************************************
- ' Show is one of TextServer's OLE Automation commands. It causes
- ' TextServer to be activated and visible.
- '*****************************************************************
- ' NOTE: TextServer (and most OLE Automation apps) are invisible
- ' by default, so you must make them visible by some method
- ' if you want the user to see the application. If the user
- ' doesn't need to see the application, then it isn't
- ' necessary to make it visible.
- '*****************************************************************
- TextServer.Show
- Show
- End Sub
- '*********************************************************************
- ' This proceedure just loads the text box with some sample text.
- '*********************************************************************
- Private Sub LoadText()
- Dim Source%, res$
- Source = FreeFile
- Open App.Path & "\sample.txt" For Input As Source
- res = Input(LOF(Source), Source)
- Text1 = res
- Close Source
- End Sub
- '*********************************************************************
- ' This proceedure demonstrates how you can automatically register (or
- ' re-register) a application without any interaction from the user.
- '*********************************************************************
- Private Sub RegisterTextServer()
- Dim sTemp$, Source%, RegFile$
- '*****************************************************************
- ' The entire contents of sTemp was created by opening a .REG file
- ' in Notepad, and inserting text before and after each line. That
- ' text was then pasted into VB, and Notepad was closed without
- ' saving. In addition, any of the lines that pointed to the .EXE,
- ' were updated to reflect the path to the program (in this case
- ' App.Path).
- '*****************************************************************
- sTemp = "REGEDIT" & vbCrLf
- sTemp = sTemp & "; This .REG file is used to properly register TextServer." & vbCrLf
- sTemp = sTemp & "COleObjectFactory::UpdateRegistryAll." & vbCrLf
- sTemp = sTemp & "" & vbCrLf
- sTemp = sTemp & "HKEY_CLASSES_ROOT\.txt = Text.Document" & vbCrLf
- '*****************************************************************
- ' The next 2 lines are combined into one line in the file that
- ' points to the path where TEXTSVER.EXE is stored. If the
- ' system registry doesn't point to a vaild path, DDE connections
- ' will always fail uvbCrlfess TextServer is already running.
- '*****************************************************************
- sTemp = sTemp & "HKEY_CLASSES_ROOT\Text.Document\shell\open\command = "
- sTemp = sTemp & App.Path & "\TEXTSVER.EXE %1" & vbCrLf
- sTemp = sTemp & "HKEY_CLASSES_ROOT\Text.Document\shell\open\ddeexec = [open(""%1"")]" & vbCrLf
- sTemp = sTemp & "HKEY_CLASSES_ROOT\Text.Document\shell\open\ddeexec\application = TEXTSVER" & vbCrLf
- sTemp = sTemp & "" & vbCrLf
- sTemp = sTemp & "HKEY_CLASSES_ROOT\Text.Document = Text Document" _
- & vbCrLf
- sTemp = sTemp & "HKEY_CLASSES_ROOT\Text.Document\CLSID = {F15017A0-8245-101B-95FE-00AA0030472F}" & vbCrLf
- sTemp = sTemp & "" & vbCrLf
- sTemp = sTemp & "HKEY_CLASSES_ROOT\CLSID\{F15017A0-8245-101B-95FE-00AA0030472F} = Text Document" & vbCrLf
- '*****************************************************************
- ' Once again, the next two lines point to the path where
- ' TEXTSVER.EXE is stored. If the system registry doesn't point
- ' to a vaild path, CreateObject will always fail uvbCrlfess TextServer
- ' is already running.
- '*****************************************************************
- sTemp = sTemp & "HKEY_CLASSES_ROOT\CLSID\{F15017A0-8245-101B-95FE-00AA0030472F}\LocalServer = "
- sTemp = sTemp & App.Path & "\TEXTSVER.EXE" & vbCrLf
- sTemp = sTemp & "HKEY_CLASSES_ROOT\CLSID\{F15017A0-8245-101B-95FE-00AA0030472F}\ProgId = Text.Document" & vbCrLf
- '*****************************************************************
- ' Create the .REG file on the end users hard drive.
- '*****************************************************************
- Source = FreeFile
- RegFile = App.Path & "\TEXTSVER.REG"
- '*****************************************************************
- ' Clear the file
- '*****************************************************************
- Open RegFile For Output As Source
- Close Source
- '*****************************************************************
- ' Create the reg file
- '*****************************************************************
- Open RegFile For Binary As Source
- Put Source, , sTemp
- Close Source
- '*****************************************************************
- ' Run RegEdit with the .REG file to automatically register it.
- ' If the app was already registered, your file will update the
- ' registry with any changes.
- '*****************************************************************
- Shell "regedit.exe /s " & RegFile, vbMinimizedNoFocus
- End Sub
-