68 OLE and DDE |
|
Word 2003 Unicode Conversion Macros
BibleWorks has rudimentary DDE capabilities. They allow you to fetch BibleWorks verse data and status information from other applications via DDE links. The available commands are shown below. Each command has a sample showing how it is used in a Word for Windows macro.
BibleWorks can also function as a simple OLE Server. This permits you to control BibleWorks from any application that supports OLE Automation, including Word, Excel, Internet Explorer. Using JavaScript you can control BibleWorks from an HTML file. The commands at the present time are basic and mirror the DDE functionality in most respects. The examples below show both DDE and JavaScript (OLE) versions of the commands.
Command: GetCurrentVerse
Function: Returns a string containing the current verse reference, preceded by the current version descriptor. For example: <KJV Rom 8:28>
Word DDE Example: a$ =
DDERequest(ChanNum,"GetCurrentVerse")
Word OLE Example: a$ = bwObj.GetCurrentVerse()
Command: SetVersions
Function: Sets the current search version and display versions. The string sent to BibleWorks should contain a list of version specifiers, with the search version first. For example you might send the following: <KJV KJV GNT WTT VUL LXT>
Word DDE Example: DDEExecute ChanNum,
"SetVersions KJV KJV ASV GNT"
Word OLE Example: bwObj.SetVersions("KJV KJV ASV GNT")
Command: GetVersions
Function: Returns the current search and display versions in BibleWorks in the form of a string of version specifiers with the current search version first. See "SetVersions" above.
Word DDE Example: a$ =
DDERequest(ChanNum,"GetVersions");
Word OLE Example: a$ = bwObj.GetVersions()
Command: GoToVerse
Function: Causes BibleWorks to load the specified verse. It also loads the Browse Window into the Windows Clipboard so that it is available to the calling application.
Word DDE Example: DDEExecute ChanNum, "GoToVerse
Mat 1:1"
Word OLE Example: bwObj.GoToVerse("Mat 1:1")
Command: Lookup
Function: Causes the string following the command to be looked up in the currently set search version.
Word DDE Example: DDEExecute ChanNum, "Lookup moses"
Word OLE Example: bwObj.Lookup("moses")
Command: IgnoreErrors
Function: Prevents BibleWorks from displaying a Window when GoToVerse is executed with an invalid verse reference. It has two Options - TRUE and FALSE.
Word DDE Example: DDEExecute ChanNum,
"IgnoreErrors TRUE"
Word OLE Example: bwObj.IgnoreErrors(1)
Command: ClipGoToVerse
Function: If set to TRUE the GoToVerse option will also copy the current Browse Window to the system clipboard. It has two Options - TRUE and FALSE. The default is TRUE.
Word DDE Example: DDEExecute ChanNum, "
ClipGoToVerse TRUE"
Word OLE Example: bwObj.ClipGoToVerse(1)
Command: AutoQuit
Function: If set to TRUE BibleWorks will quit after all commands have been processed.
Word DDE Example: DDEExecute ChanNum, " AutoQuitTRUE"
Word OLE Example: bwObj.AutoQuit(1)
The following example is a do-nothing Word for Windows Macro that illustrates how to use the DDE functions.
Sub MAIN()
Dim a As String
ChanNum = DDEInitiate("bw900", "Commands")
DDEExecute ChanNum, "GoToVerse Mat 1:1"
MsgBox "You should be at Matthew 1:1"
a = DDERequest(ChanNum, "GetCurrentVerse")
MsgBox "The current verse is " + a
DDEExecute ChanNum, "SetVersions KJV KJV ASV BGT"
MsgBox "The current search version should be KJV."
a = DDERequest(ChanNum, "GetVersions")
MsgBox a
DDEExecute ChanNum, "Lookup moses"
MsgBox "I just looked up Moses"
DDETerminate ChanNum
End Sub
The following is another example that fetches a verse from BibleWorks and inserts it into a Word for Windows document using DDE.
The following is a Word 2003 Macro:
Sub Main()
ChanNum = DDEInitiate("bw900", "Commands")
Verse$ = InputBox("Enter Reference to Insert:", "BibleWorks")
DDEExecute ChanNum, Verse$
DDETerminate ChanNum
Selection.Paste
End Sub
In Word 2000 Basic macro would look like this:
Sub MAIN
Begin Dialog UserDialog 218, 118, "BibleWorks"
TextBox 10, 26, 189, 18, .TextBox1
Text 8, 6, 176, 13, "Enter Reference to Insert:"
OKButton 115, 56, 88, 21
CancelButton 114, 81, 88, 21
End Dialog
Dim VerseDlg As UserDialog
DisableInput
ChanNum = DDEInitiate("bw900", "Commands")
Dialog VerseDlg
Verse$ = VerseDlg.TextBox1
DDEExecute ChanNum, Verse$
EditPaste
DDETerminate ChanNum
End Sub
The following is an OLE Automation example also in Word.
Sub Main()
Dim bwObj As Object
Set bwObj = CreateObject("bibleworks.automation")
bwObj.AutoQuit (0)
bwObj.GoToVerse ("Mat 1:5")
MsgBox "You should be at Matthew 1:5"
a$ = bwObj.GetCurrentVerse()
MsgBox "The current verse is " + a$
bwObj.SetVersions ("KJV KJV ASV BGT")
MsgBox "The current search version should be KJV."
a$ = bwObj.GetVersions()
MsgBox a$
bwObj.Lookup ("moses")
MsgBox "I just looked up Moses"
Set bwObj = Nothing
End Sub
BibleWorks contains support internally for converting BibleWorks non-Unicode fonts to Unicode. If you have Word Documents which use BibleWorks non-Unicode fonts you can access the conversion routines through the following Word Macros. They have been tested only in Word 2003. To implement them just copy the blue text below into the Word Macro editor. If you want to use a different Unicode font you will need to edit the font names in the calling routines.
Sub ConvertAllBwGrk2Unicode()
ConvertBwGrk2Unicode "bwgrkl", "Arial Unicode MS", True
End Sub
Sub ConvertAllBwHeb2Unicode()
ConvertBwHeb2Unicode "bwhebb", "Ezra SIL", True
End Sub
Sub ConvertAllBwLex2Unicode()
ConvertBwLex2Unicode "bwlexs", "Arial Unicode MS", True
End Sub
Sub ConvertAllBwSym2Unicode()
ConvertBwSym2Unicode "bwsymbs", "Arial Unicode MS", True
End Sub
Sub ConvertNextBwGrk2Unicode()
ConvertBwGrk2Unicode "bwgrkl", "Arial Unicode MS", False
End Sub
Sub ConvertNextBwHeb2Unicode()
ConvertBwHeb2Unicode "bwhebb", "Ezra SIL", False
End Sub
Sub ConvertNextBwLex2Unicode()
ConvertBwLex2Unicode "bwlexs", "Arial Unicode MS", False
End Sub
Sub ConvertNextBwSym2Unicode()
ConvertBwSym2Unicode "bwsymbs", "Arial Unicode MS", False
End Sub
The following are support routines for the previous subroutines.
Sub ConvertBwHeb2Unicode(fromfont$, tofont$, doentirefile)
Dim o As Object
Dim ucstr As Variant
ReDim ucstr(1024) As Long
If (doentirefile = True) Then Selection.HomeKey Unit:=wdStory
Set o = CreateObject("bibleworks.automation")
Application.ScreenUpdating = True
icheck = 0
While (icheck = 0)
Selection.Find.ClearFormatting
With Selection.Find
.Font.Name = fromfont$
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchByte = False
.CorrectHangulEndings = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
If (Selection.Find.Execute = False) Then
icheck = 1
Else
istart = 1
iend = Selection.Characters.Count
ReDim ucstr(3 * iend + 2) As Long
ucstr(1) = iend
For i = istart To iend
ucstr(i + 1) = Asc(Selection.Characters(i))
Next i
o.BwHebb2Unicode ucstr
rem Selection.Delete
Application.Keyboard (1037)
With Selection.Font
.NameFarEast = "SimSun"
.NameAscii = "Arial"
.NameOther = "Arial"
.Name = "Arial"
.Size = 10
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
.DisableCharacterSpaceGrid = False
.EmphasisMark = wdEmphasisMarkNone
.SizeBi = 14
.NameBi = tofont$
.BoldBi = False
.ItalicBi = False
End With
For i = 1 To ucstr(1)
s$ = ChrW(ucstr(i + 1))
Selection.TypeText Text:=s$
Next i
Application.Keyboard (1033)
End If
If (doentirefile = False) Then icheck = 1
Wend
Application.ScreenUpdating = True
Set bwutil = Nothing
End Sub
Sub ConvertBwGrk2Unicode(fromfont$, tofont$, doentirefile)
Dim o As Object
Dim ucstr As Variant
ReDim ucstr(1024) As Long
If (doentirefile = True) Then Selection.HomeKey Unit:=wdStory
Set o = CreateObject("bibleworks.automation")
icheck = 0
While (icheck = 0)
Selection.Find.ClearFormatting
With Selection.Find
.Font.Name = fromfont$
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchByte = False
.CorrectHangulEndings = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
If (Selection.Find.Execute = False) Then
icheck = 1
Else
istart = 1
iend = Selection.Characters.Count
ReDim ucstr(3 * iend + 2) As Long
ucstr(1) = iend
For i = istart To iend
ucstr(i + 1) = Asc(Selection.Characters(i))
Next i
o.BwGrkl2Unicode ucstr
rem Selection.Delete
Application.Keyboard (1032)
With Selection.Font
.NameFarEast = "SimSun"
.NameAscii = "Arial"
.NameOther = "Arial"
.Name = "Arial"
.Size = 10
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
.DisableCharacterSpaceGrid = False
.EmphasisMark = wdEmphasisMarkNone
.SizeBi = 14
.NameBi = tofont$
.BoldBi = False
.ItalicBi = False
End With
For i = 1 To ucstr(1)
s$ = ChrW(ucstr(i + 1))
Selection.TypeText Text:=s$
Next i
Application.Keyboard (1033)
End If
If (doentirefile = False) Then icheck = 1
Wend
Set bwutil = Nothing
End Sub
Sub ConvertBwSym2Unicode(fromfont$, tofont$, doentirefile)
Dim o As Object
Dim ucstr As Variant
ReDim ucstr(1024) As Long
If (doentirefile = True) Then Selection.HomeKey Unit:=wdStory
Set o = CreateObject("bibleworks.automation")
icheck = 0
While (icheck = 0)
Selection.Find.ClearFormatting
With Selection.Find
.Font.Name = fromfont$
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchByte = False
.CorrectHangulEndings = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
If (Selection.Find.Execute = False) Then
icheck = 1
Else
istart = 1
iend = Selection.Characters.Count
ReDim ucstr(3 * iend + 2) As Long
ucstr(1) = iend
For i = istart To iend
ucstr(i + 1) = Asc(Selection.Characters(i))
Next i
o.BwSym2Unicode ucstr
rem Selection.Delete
Application.Keyboard (1033)
With Selection.Font
.NameFarEast = "SimSun"
.NameAscii = tofont$
.NameOther = tofont$
.Name = tofont$
.Size = 10
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
.DisableCharacterSpaceGrid = False
.EmphasisMark = wdEmphasisMarkNone
.SizeBi = 12
.NameBi = tofont$
.BoldBi = False
.ItalicBi = False
End With
For i = 1 To ucstr(1)
isetsuper = 0
If (ucstr(i + 1) < 0) Then
Selection.Font.Superscript = True
isetsuper = 1
s$ = ChrW(-ucstr(i + 1))
ElseIf (ucstr(i + 1) > 0) Then
s$ = ChrW(ucstr(i + 1))
Else
s$ = " "
End If
Selection.TypeText Text:=s$
If (isetsuper = 1) Then Selection.Font.Superscript = False
Next i
Application.Keyboard (1033)
End If
If (doentirefile = False) Then icheck = 1
Wend
Application.ScreenUpdating = True
Set bwutil = Nothing
End Sub
Sub ConvertBwLex2Unicode(fromfont$, tofont$, doentirefile)
Dim o As Object
Dim ucstr As Variant
ReDim ucstr(1024) As Long
If (doentirefile = True) Then Selection.HomeKey Unit:=wdStory
Set o = CreateObject("bibleworks.automation")
icheck = 0
While (icheck = 0)
Selection.Find.ClearFormatting
With Selection.Find
.Font.Name = fromfont$
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchByte = False
.CorrectHangulEndings = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
If (Selection.Find.Execute = False) Then
icheck = 1
Else
istart = 1
iend = Selection.Characters.Count
ReDim ucstr(3 * iend + 2) As Long
ucstr(1) = iend
For i = istart To iend
ucstr(i + 1) = Asc(Selection.Characters(i))
Next i
o.BwLex2Unicode ucstr
rem Selection.Delete
Application.Keyboard (1033)
With Selection.Font
.NameFarEast = "SimSun"
.NameAscii = tofont$
.NameOther = tofont$
.Name = tofont$
.Size = 10
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
.DisableCharacterSpaceGrid = False
.EmphasisMark = wdEmphasisMarkNone
.SizeBi = 12
.NameBi = tofont$
.BoldBi = False
.ItalicBi = False
End With
For i = 1 To ucstr(1)
isetsuper = 0
If (ucstr(i + 1) < 0) Then
Selection.Font.Superscript = True
isetsuper = 1
s$ = ChrW(-ucstr(i + 1))
ElseIf (ucstr(i + 1) > 0) Then
s$ = ChrW(ucstr(i + 1))
Else
s$ = " "
End If
Selection.TypeText Text:=s$
If (isetsuper = 1) Then Selection.Font.Superscript = False
Next i
Application.Keyboard (1033)
End If
If (doentirefile = False) Then icheck = 1
Wend
Application.ScreenUpdating = True
Set bwutil = Nothing
End Sub