Function Convert Values Class

VariantToFixedCString

Create a C string of length vCStringSize and copy vBasicString into it. Normally used to allocate a string with enough space to receive a string value back from Windows API function calls.

Signature (Visual Basic / VBA)

Public Function VariantToFixedCString( _
      Optional ByVal vBasicString As Variant _
    , Optional ByVal vCStringSize As Variant _
    ) As String

Code Example

    VariantToFixedString("Word", 40) = "Word" + String$(36, 0)
    VariantToFixedString("Word", 4) = "Wor" + Chr$(0)
    VariantToFixedString(123456, 4) = "123" + Chr$(0)
    VariantToFixedString("", 4) = String$(4, 0)
    VariantToFixedString(Null, 4) = String$(4, 0)

Parameters

Parameter Description
vBasicString The value which is to be converted into a fixed-length, nil-terminated C string. Function returns a string containing a single Nil (Chr$(0)) character if vBasicString is Null. vBasicString defaults to an empty string if it is missing or Null or cannot be fixed up to a String.
vCStringSize The size in characters of the fixed-length result string that this function will produce. vCStringSize defaults to 255 if it is missing or Null or cannot be fixed up to a number.

Notes & Version History

Note The VariantToCString function is used to prepare strings to be passed to Windows API functions which do not modify their arguments.