3

One of my Excel VBA scripts cycles through all the versions of a particular ClearCase element to see if it was merged. This fails when a particular version was deleted using an rmver (using destructive deletes is not recommended but we do resort to this on rare occasions to get a developer out of a dependency).

In DOS, the following works perfectly:

IF EXIST M:\View\LAMI\build.xml@@\main\lc_adhoc_dev\3 ECHO Yes
Yes

To do this in VBA, I tried using the Dir method to check for the presence of a particular version:

Dim elementVersion As String
elementVersion = "M:\View\LAMI\build.xml@@\main\lc_adhoc_dev\3"

If Len(Dir(elementVersion)) > 0 Then
  ' Version exists
Else
  ' Version does not exist
End If

However, that results in an error "Bad file name or number":

I also tried the FileExists method of the fso object:

Dim elementVersion As String
elementVersion = "M:\View\LAMI\build.xml@@\main\lc_adhoc_dev\3"
Dim fsoObj As Object
Set fsoObj = CreateObject("Scripting.FileSystemObject")

If fsoObj.FileExists(elementVersion) = True Then
  ' Version exists
Else
  ' Version does not exist
End If

However, that call always returns False. It appears all these methods have issues with the ClearCase MVFS virtual M: drive. Is there anything else I could try?

Jozef
  • 303
  • 1
  • 11
  • I'll post an answer in a few hours, but check out `cleartool get` (http://stackoverflow.com/a/5381646/6309): if you can get and copy an old version to your C:\ drive, then that version exists. If the `cleartool get` fails... the version does not exist. – VonC Apr 11 '17 at 14:10
  • cleartool get only works for files. I need to check non-existing versions of directories too (I updated my question: changed "file" to "element"). Also, – Jozef Apr 11 '17 at 16:13
  • Also, I'm trying not to have to rely on the Err object, i.e. not use a cleartool command that fails when it encounters a non-existing version (such as get or descr). – Jozef Apr 11 '17 at 16:29
  • I was about to suggest describe ;) – VonC Apr 11 '17 at 16:30
  • In your case you should rely on err – VonC Apr 11 '17 at 16:31

1 Answers1

1

I'm trying not to have to rely on the Err object, i.e. not use a cleartool command that fails when it encounters a non-existing version (such as get or descr).

That is precisely what you should rely on, unless you have constraint (like testing thousands of elements per second, or other performance bottleneck)

cleartool describe can be applied on an extended pathname and will fail if it does not exist.

As commented by Brian Cowan, you can check if Excel VBA can call commands from the ClearCase Automation Library (CAL).
I have used CAL in VB Script before.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • RIght: I want to make sure a particular version exists before running a describe on it! Interesting that this (checking for the existence of a particular version without using error handlers) can be done in DOS Batch and not in VBA. Guess I have no choice but to use the Err object. – Jozef Apr 11 '17 at 18:45
  • 1
    @Jozef I understand. But here, describe is used bith to check if it exists, and, if it does, to describe it. – VonC Apr 11 '17 at 18:47
  • 1
    If you're using 32-bit Excel, you might want to look at the ClearCase Automation Library (CAL). The "doc" is the cc_cal.chm file in C:\Program Files (x86)\IBM\RationalSDLC\ClearCase\bin... This unfortunately mean that you need to install the help file viewer. – Brian Cowan Apr 11 '17 at 20:28
  • @VonC I'm using CAL too in these scripts (I pass most commands through a cleartool object.) I just wanted to prevent a cleartool descr command from generating an error when a particular version does not exist. Since there apparently is no way to do that my original question was answered. I check the value of Err.Number to see if a version exists and no longer exit the script when it doesn't. – Jozef Apr 12 '17 at 03:27