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

Timothy_Cosgrif
Star Collaborator
Star Collaborator

Yes, that should work.

Really, any form of looping should work when iterating keywords from a regular for loop to the elusive do/while loop.

Have you run this in a test system to verify that it does what you need it to do?

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

I do not have an environment to test this in. I copied this source code from a tutorial, but I modified a few lines... in particular, wishing to avoid this:

 

Dim lVariable

lVariable = Object.Variable

 

Instead, I would rather just use Object.Variable

Can you clarify that I can do that?

Also I'm still learning how to post articles here and make my posts visible.... I'm glad you found it, and have patience with me until I become an expert in using this forum.

 

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

I'm new to the forum, apologies for multiple posts. I would like to learn how to delete a post, though.

 

Patrick_Ramser
Star Contributor
Star Contributor

I think that may just be a caveat of using Option Explicit (which you aren't using in the above script).

Implicitly creating variables should be fine without all the need to dimension them for what you want to do, I believe. I'm no VB Script expert! So take that with a grain of salt.

Here's an article on w3schools further explaining some of that stuff: http://www.w3schools.com/vbscript/vbscript_variables.asp