How can I....? (VB scripting)

<< Working with collections ...
Back to Portfolio FAQ index
Working with MultiValue ( ... >>

Here is an assortment of odd VB related snippets that the available (PDF) documentation and inspection via the object browser don't really make clear.

What is the 'PortObj' in the code samples on this page?

The 'PortObj' cited below is a generic reference to the Portfolio Document object; depending on the version you are using you will need to set a reference to:

How do I get a Count of (open) Galleries?

PortObj.Document.Gallery(index).Count (not too intuitive!)

In v7, the Count is the count of galleries as seen in the Galleries panel. In a newly opened catalogue the Count is 2 (All Items, and Last Cataloged) with any saved Galleries numbering from 3 onwards. When a Find is run for the first time in a session, the Find Gallery is inserted in the array as #3 and all saved Custom Galleries shift up one. consider also the effects on numbering of inserting or renaming custom Galleries as this will alter the Gallery sort and thus the Gallery index number.

In v6 and earlier, the Count returns (Long) the number of open Galleries from all open catalogues. Huh? Let's say you have Catalogue A open with 5 Galleries of which 2 are opened and Catalogue B with 7 Galleries of which 3 are opened. The Count code above would return 5 (2xA and 3xB). This demonstrates 2 points. Firstly, in scripting there is no 'Catalogue' entity, just a number of Galleries. Secondly, the automation library is blind to existing but unopened Galleries (did you answer '12' above?). To use a Gallery it must be open already as discussed in more detail here.

The second of the 2 code samples above is highly counter-intuitive as the Gallery(index) appears to count other Galleries outside itself whereas most function/properties are inwardly focused. Although this code works it is very confusing and I'd recommend using the first example - especially if sharing the code with others.

How do I set a particular Gallery as the active one?

PortObj.SetActive("Demo.fdb - Startup")

Note you must use the full Gallery name, i.e. "Demo.fdb - Startup" and not just "Startup", for a Gallery called 'Startup' in Catalogue 'Demo.fdb'. If confused, be aware you can check a Gallery's 'full' name by opening the Gallery in the client. The Gallery's 'full' name is shown in the Gallery window's caption bar.

If the Gallery called is not open, no error is generated but no error occurs. If you set an integer variable to catch the return value from the SetActive function...

intError = PortObj.SetActive("Demo.fdb - Startup") the case of the called Gallery not being open, the Error value 27 is returned equating to Portfolio VB error kScriptGalleryNotFound, i.e. "Gallery not found". If successful, an Error value of 0 is returned.

By the same naming logic as for GetActive, the string returned by the Portfolio_V5.Document.GetActive function will be the 'full' name, as it is also for Gallery(index).GalleryName (see below)

How do I get a Count of Records in (the active) Gallery?

lngTest = PortObj.Gallery(index).AllRecords().Count

The count returns a Long. Note that you actually access the Records or Selection objects via the AllRecords() or SelectedRecords() objects. All 4 classes (objects) share the same members. Quite why this methodology was employed is not clear - there seems to be no direct way to use the Records/Selection objects despite it being shown in the Object Browser. As you'd suppose the record count is for the active (current) Gallery though bear in mind that you cannot simply assume Gallery(index).AllRecords() is the same as all the records in the Catalogue unless you've set the Gallery to do so already (e.g. do a 'find all' Find first).

Although you must include the () empty brackets in the object reference, do not put anything in the brackets. If you enter a number there you then address a particular record - see the next question.

How do I get a Count of Fields in (the active) Gallery's Catalogue?

lngTest = PortObj.Gallery(index).AllRecords(index).Count

The count returned includes both built-in (#1-29) and custom (#30 upwards) fields. Custom fields are indexed in the chronological order in which they were added to the Catalogue.

What does Gallery.CatalogName return?


A string, e.g. "C:\folder\Demo.fdb", with the full path and file name.

What does Gallery.GalleryName return?


A string, e.g. "Demo.fdb - Startup". The string contains both the Catalogue filename and the Gallery name separated by a space/hyphen/space combo. This format looks odd at first but does reflect the fact that the automation library has no specific Catalog object.

So how do I get just the Catalogue or Gallery name on it's own?

For the Catalogue name, parse it from either the path or the 'full' name. For the Gallery name, parse it from the 'full' name. You may finding yourself wanting to join/separate the two names if you want to do things like list the open Galleries.

How do I activate an (open) Gallery with Gallery.Activate?

PortObj.Gallery(index).Activate in...
...activates Gallery index #2.

Galleries appear to be ordered as opened. If any Galleries are closed, the Portfolio document object is not updated - even if a Count is done - and an automation error will occur. It is better to use Document.SetActive instead as this seems less prone to such lack of a proper refresh of object data.

What does the Gallery.NumFound return?

A Long that is the count of the records found in a search (i.e. 'Find'). The NumFound is only populated whilst the Find is active and is otherwise zero. Thus:

' Search all Records in Gallery #1 for Filenames beginning with "01_" and display the in the current Gallery
strQuery = "Filename" & vbTab & "Starts with" & vbTab & "01_"
intFind = PortObj.Gallery(1).Find(strQuery,True, False)

' Note that the Function returns the number of records found and populates Gallery.NumFound
MsgBox "intFind = " & intFind & vbCrLf & "NumFound = " & PortObj.Gallery(1).NumFound
' You should find that PortObj.Gallery(1).NumFound = CLng(intFind) if check at this point

What does the Gallery.Busy Property indicate?

The purpose of this is to indicate that the Gallery is in use cataloguing files. However, it always returns zero and is (as at v6.02) buggy and not operating as intended. The main aim is to allow for scripting into a catalogue that may be subject to protracted cataloguing operations when doing other tasks would be impossible or unadvisable. This bug has been reported to Extensis.

What does the Record.EnsureVisible Sub do?

Note that this only works fully in List View. The Sub selects only a single record index, i.e.


The result is to deselect any currently selected record(s), select the specified record and the client interface's List View (only) is scrolled to display the selected record. In Thumbnail or Record View, the specified record is selected but the display is not changed.

How can I easily change the host client's access level?

Note - This only works with level-based access with no passwords set. With some addition the technique could probably be adapted to use passwords and with user-based access; you need to note the tab order on the Access dialog to know the additional keystrokes and strings to pass.

Have Portfolio & your catalogue open. In a new VB project add a button cmdDoSendKeys and run the code below:

Private Sub cmdDoSendKeys_Click()
' For v6, in v5 the keys needed might differ
' Drive the Portfolio interface to insert placeholder

AppActivate "Portfolio"
' send Alt+C to open "Catalog" menu
SendKeys "%+(C)", True
' Send Arrow Down key 8 times to select "Access" menu (15 times if in v5)
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True

' Send Enter to open "Access" Dialog
SendKeys "~", True
' Send Arrow Down key 2 times to select "Editor" mode
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True

' Send Enter to set "Editor" mode
SendKeys "~", True
End Sub

In case you're wondering - you can't use SendKeys to pass application-specific keyboard shortcuts, e.g. Ctrl+J to open the Access dialog.

Question: How can I....? (VB scripting) [FAQ00227.htm]
Last Update:- 01 June 2006

<< Working with collections ...
Back to Portfolio FAQ index
Working with MultiValue ( ... >>

Quick Search of PortfolioFAQ (word, words or phase): or try the Advanced Search

User-to-User Forums  |  Report error/typo/broken link  |  Request new topic  |  Ask a question

Site and articles © Mark Anderson 2001-2007 - Visit my home page

This FAQ is created and maintained using
Friday logo
Friday - The Automatic FAQ Maker