This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Type Mismatch when Unserializing a TypedValue

Hey everyone!

I'm having trouble using the Unserialize function in a TypedValue object in VB Script.  I thought it might caused by the way I was moving the data to another function so I did a quick test by using the serialize function from the TypedValue of a property then trying to unserialize it right away into a new TypedValue object.

    Dim oTypedValue : Set oTypedValue = CreateObject("MFilesAPI.TypedValue")
    Dim aSerialized : aSerialized = oJobNumber.Serialize
    oTypedValue.Unserialize aSerialized, False

I'm getting a 'type mismatch' error on the unserialize function.  There's absolutely no examples of using these functions so I cannot tell why it's not working.  I'd appreciate any help anyone can provide!

Thank you,

Heather

Parents
  • I figured out why I was getting the 'Type Mismatch' error.  VBScript does not do true CHAR arrays.  When assigning the output of the Serialize command to a variable, I was losing the true character array from the function.  I was able to encode the output to a string using the System.Text.UTF8Encoding class.  I can then use the Unserialize function by converting that string back to a character array.

        Dim oEncoding : Set oEncoding = CreateObject("System.Text.UTF8Encoding")
        Dim oTypedValue : Set oTypedValue = CreateObject("MFilesAPI.TypedValue")
        Dim sSerialized : sSerialized = oEncoding.GetString(oJobNumber.Serialize)
        oTypedValue.Unserialize oEncoding.GetBytes_4(sSerialized), True

    Hope this helps someone else.

Reply
  • I figured out why I was getting the 'Type Mismatch' error.  VBScript does not do true CHAR arrays.  When assigning the output of the Serialize command to a variable, I was losing the true character array from the function.  I was able to encode the output to a string using the System.Text.UTF8Encoding class.  I can then use the Unserialize function by converting that string back to a character array.

        Dim oEncoding : Set oEncoding = CreateObject("System.Text.UTF8Encoding")
        Dim oTypedValue : Set oTypedValue = CreateObject("MFilesAPI.TypedValue")
        Dim sSerialized : sSerialized = oEncoding.GetString(oJobNumber.Serialize)
        oTypedValue.Unserialize oEncoding.GetBytes_4(sSerialized), True

    Hope this helps someone else.

Children
No Data