Author Topic: Using FileHistoryEvent  (Read 1954 times)

ggblue

  • New Members
  • *
  • Posts: 14
Using FileHistoryEvent
« on: March 21, 2015, 01:45:11 AM »
Hi,
I have a problem getting a single instance of a FileHistoryObject. Here is my sample code snippet:

' this code works (for each...)

Dim imgHistEv  As FileHistoryEvent
Dim iHE As FileHistoryEvent

For Each imgHistEv In img.History
      Debug.Print vbTab;imgHistEv.ID ;vbTab;imgHistEv.Timestamp ; vbTab;imgHistEv.UserName
Next


' These three lines don't work as expected, cause their result is 'nothing'. (Error No 10094 objectvar is nothing)

Set iHE = img.History(1)
Set iHE  = img.History.item(1)

Debug.Print  img.History(1).UserName

In the HelpFile is the object descripted as:
'The file history is a collection of FileHistoryEvent instances. You can iterate over the events in the FileHistory using for each or access individual elements via the Item method. Events are sorted in ascending order by date and time, with the first event at the first position in the collection.'

The property ITEM is here descripted as: The 1-based index of the element you want to access. This is the default property so you can shorten Item(n) to (n). Return Value FileHistoryEvent The requested event instance.

Other similar Objects  (Collection - > Member of the Collection)  work as expected.

Some helping tipps are really welcome....
ggblue

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 30082
Re: Using FileHistoryEvent
« Reply #1 on: March 21, 2015, 07:42:23 AM »
Have you looked at the File History sample script?

I think it shows quite well how to use these classes. It displays a HTML dialog which a table showing the history of the focused file.

ggblue

  • New Members
  • *
  • Posts: 14
Re: Using FileHistoryEvent
« Reply #2 on: March 21, 2015, 01:28:44 PM »
Hi Mario,
the sample script ('File History.bas')doesn't help me because it is based on a For...Each loop too.

I only need in my code the first FileHistoryEvent instance of the collection img.history.
My code doesn't work well, cause the instance of the FileHistoryEvent (iHe) seems not be initialized by the "Set" command.

Dim img As IMatch.File
Dim iHE As FileHistoryEvent

Set iHE = img.History(1)
Set iHE  = img.History.item(1)

Debug.Print  img.History(1).UserName


Any hint would be great.
ggblue



ubacher

  • Oldtimer
  • ****
  • Posts: 2379
Re: Using FileHistoryEvent
« Reply #3 on: March 21, 2015, 01:33:39 PM »
I would try:
Dim iHE As NEW FileHistoryEvent

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 30082
Re: Using FileHistoryEvent
« Reply #4 on: March 21, 2015, 04:10:12 PM »
Seems not to work.
I suggest you file a bug report so I can look into this at some later time.

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 30082
Re: Using FileHistoryEvent
« Reply #5 on: March 21, 2015, 04:35:12 PM »
Forget it. Fixed it already for the next release. Just a missing ! in the source code.

For a simple work-around, do a regular for each x in y loop and break out of the loop after the first iteration. This gives you the first item in the history as well.

Code: [Select]
Dim hist As FileHistory
Set hist = Application.GetFileWindow(imfwtCurrent).FocusedFile.History

Dim e As FileHistoryEvent

For Each e In hist
Exit For
Next

Debug.Print e.UserName
« Last Edit: March 21, 2015, 07:30:58 PM by Mario »

ggblue

  • New Members
  • *
  • Posts: 14
Re: Using FileHistoryEvent
« Reply #6 on: March 21, 2015, 07:10:39 PM »
Thanks a lot Mario,
the workaround is ok and I'm happy...

ggblue