Why does UCase give Type Mismatch error?

Hi, I'm using an event handler to control filenames that are drag-dropped onto our vault. Part of this is I wish to force document names to be UPPERCASE

This works:
Vault.ObjectFileOperations.RenameFile ObjVer, fVerNew, szLeftTrim, szExtension, false

But this gives a Type Mismatch error, and I don't know why:
Vault.ObjectFileOperations.RenameFile ObjVer, fVerNew, UCase(szLeftTrim), szExtension, false

Any ideas? Many thanks

  • Hi, I believe it is...?
    Here's some of the preceeding code:

    Dim pDocName : pDocName = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("H.Property.DocumentName")
    Dim szDocName : szDocName = oPropVal.SearchForProperty(pDocName).TypedValue.DisplayValue
    Dim iCorrectLength : iCorrectLength = 22 ' Document Naming format: 12345-78-01-345-789012


    ' Get all Files within the current document Object
    Dim ObjectFileCollection : Set ObjectFileCollection = Vault.ObjectFileOperations.GetFiles(ObjVer)
    Dim iFileCount : iFileCount = ObjectFileCollection.Count

    ' Loop through each File within the current document Object
    For i = 1 To iFileCount

    ' Iteratively get each individual file within the current document Object
    Dim CurrentObjectFile : Set CurrentObjectFile = ObjectFileCollection.Item(i)

    Dim iTitleLength : iTitleLength = Len(CurrentObjectFile.Title)
    Dim szFullTitle : szFullTitle = CurrentObjectFile.Title
    Dim szLeftTrim : szLeftTrim = Left(CurrentObjectFile.Title,iCorrectLength)
    Dim szExtension : szExtension = CurrentObjectFile.Extension
    Dim szUCase : szUCase = UCase(szLeftTrim)

  • It's hard to diagnose without seeing all the code in context (honestly: being able to run it is the most useful in situations like this), but UCase takes a string, and "type mismatch" indicates that the type wasn't what was expected.  Perhaps the full stack trace would help, but my gut is that the value being provided is not valid in some way.

    You could try this:

    Vault.ObjectFileOperations.RenameFile ObjVer, fVerNew, UCase(szLeftTrim & ""), szExtension, false

    (concatenating the string could force VBScript to convert it).

    Otherwise you may need to do some debugging.  In VBScript this will mean placing Err.Raise to show data, and testing to see what various values are.

  • Ok, thanks

    I did try Err.Raise and got document names, as I was expecting

    Is there a good way of finding out what Type a variable actually is, in an err.raise?

  • I have literally just closed my laptop and uttered the phrase "That's it, I'm on holiday!", so I may not be able to give you as much guidance as normal.

    VBScript is not typed in the same way as languages like C#, so it's often not easy to get a true type. It also doesn't give you the ability to debug code as you can with the Vault Application Framework. VarType may be a possibility.

    Did you try with the concatenation to force the conversion? I've had to use this trick when dealing with potential null values before, for example (although with your posted snippets I don't see how it's be null). However: that's a shot in the dark. Posting the full script may give someone the ability to spot what's going on (not me, as I'm on holiday!), but adding debugging statements is probably the fastest way to see what's happening here. 

  • Will try concat tomorrow
    Many thanks & Enjoy holiday Slight smile

  • Solved, it was because fVerNew wasn't defined at that point
    It was in a different branch of the IF statements, so wasn't being executed where I had the RenameFile at that point

    Many thanks + to Vesa who helped my support ticket