cancel
Showing results for 
Search instead for 
Did you mean: 

OnBase API Exam: Automation using VB Scripts

Terry_Vantreese
Champ in-the-making
Champ in-the-making
' My questions are in the comments.
' Sometimes I like to avoid creating unnecessary variables if I can easily access information that already exists.
 
Sub Main35()
Dim oApplication = CreateObject("OnBase.Application")
Dim lKeyCount
lKeyCount = oApplication.CurrentDocument.Keywords.Count 'Will this work?
 
Dim sMessage
Dim oKeyword
Dim lLoop
For lLoop = 0 to lKeyCount - 1
    Set oKeyword = oApplication.CurrentDocument.Keywords.Item(lLoop) 'Can I do this?
    sMessage = sMessage & oKeyword.Name & " = " & oKeyword.Value & vbNewline
End For
 
MsgBox sMessage, vbInformation + vbOKonly, "Returned Keywords from Document " & oApplication.CurrentDocument.Handle
 
End Sub
5 REPLIES 5

Terry_Vantreese
Champ in-the-making
Champ in-the-making

Thanks to everyone who contributed to answering this question. When I was new (and still am new) to this Forum, I posted this question on the wrong forum, then I posted it again on the correct forum, but was unable to delete this question from the wrong forum. It eventually got moved, so I have this question posted twice. I apologize for that.

I received many responses, but looking at this code, it is a very basic and simple form using easy code sample, and even in its simple form, it is not complete, but it only contains a portion of the code in order to stage my question. I was hoping that using a simple code would bring more focus to the question, instead of overall how to solve this question.

In many examples and walk throughs, I see this pattern:

Dim (a list of variables up to 4 lines of code...)

oApplication = CreateObject("OnBase.Application")

oDocument = oApplication.CurrentDocument

oColKeywords = oDocument.Keywords

lKeyCount = oColKeywords.Count

I noticed that this was a lot of code and therefore I asked if it could be simplified into something like this...

Dim (oApplication and lKeyCount variables in 2 lines of code...)

oApplication = CreateObject("OnBase.Application")

lKeyCount = oApplication.CurrentDocument.Keywords.Count

On another post, someone answered that it could be done that way. And it was an answer that I was satisfied with.

Thanks,