Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Convert variant to string.

garry_fotheringham
445 Views

I am trying to write a subroutine to convert a variant to a string but I am not having any success. I would be grateful for any assistance.

The code I have come up with so far is:

subroutine

VariantToString(V, Str)

use ifwinty

use ifcom

implicit none

type(variant), intent(in):: V

character(len=*), intent(out):: Str

integer*4:: Hr

select case (V%varVal%vt)

case (VT_BSTR)

Hr = ConvertBSTRtoString( V%varVal%bstrVal, Str )

if ( Hr .ne. S_OK ) then

Str = ""

end

case default

Str = ""

end select

end

0 Kudos
1 Reply
anthonyrichards
New Contributor III
445 Views

I think you ought to define a length foryour character buffer. Try

CHARACTER(100) STR

and see if that works. I assume ConvertBSTRtoString is defined in one of the IVF modules you are USEing, along with S_OK and VT_BSTR etc. ? There should be a routine or function for determining the length of the bit-string buffer, so that you can test if your character string buffer is large enough to take the bit string. If not, you can do it using

INTEGER(4) strbufflen
POINTER (pString, strbufflen)
...

pString=V%varVal%bstrVal - 4

The bit-string pointer 'V%varVal%bstrVal' points to the first character in the bit string, butthe bit string itselfis preceded by 4-bytes that stores the length of the bit string buffer, so point 'pString' to the first of these 4 bytes, after which the bit-string lengthwillbe accessable as 'strbufflen'.

0 Kudos
Reply