Search code examples
vbaclearcase

Check ClearCase version existence in VBA


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?


Solution

  • 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.