contents   index   previous   next



Variant casting functions

 

f90VB Modules

 

f90VBDefs, f90VBVariants

Summary

 

This is a group of functions that return the content of a variant coerced to the specified Fortran type. Functions included in this group are listed below, under the Syntax section.

Syntax

 

logical function VariantToLogical (VarSrc, iRet, lcid, flags)
integer(LONG_KIND) VariantToInteger (VarSrc, iRet, lcid, flags)
real(FLOAT_KIND) VariantToReal (VarSrc, iRet, lcid, flags)
real(DOUBLE_KIND) VariantToDouble (VarSrc, iRet, lcid, flags)
integer(BSTRHNDL_KIND) VariantToBString (VarSrc, iRet, lcid, flags)
type(CURRENCY) VariantToCy (VarSrc, iRet, lcid, flags)
type(DECIMAL) VariantToDEC (VarSrc, iRet, lcid, flags)

All functions share the same arguments as below:

 

type(VARIANT),intent(in)::  VarSrc
integer(HRESULT_KIND),intent(out),optional:: iRet
integer(LCID_KIND),intent(in),optional:: lcid
integer(WORD_KIND),intent(in),optional:: flags

Arguments

 

VarSrc [Input]

Source variant. Must be an initialized variant.

lcid [Input/Optional]

A locale identifier.

 

flags [Input/Optional]

Flags that control the coercion of VarSrc. The only defined flag is VARIANT_NOVALUEPROP, which prevents the function from attempting to coerce an object to a fundamental type by getting the object’s Value property.

 

iRet [Output/Optional]

Upon return, iRet contains S_OK or an error code. See comments for more information.

Comments

 

The following are short descriptions of the return values of these functions:

 

 

Function Returned value
VariantToLogical A Fortran logical value resulting from the coercion of VarSrc.
VariantToInteger A Fortran long integer value resulting from the coercion of VarSrc.
VariantToReal A Fortran single-precision real value resulting from the coercion of VarSrc.
VariantToDouble A Fortran double-precision real value resulting from the coercion of VarSrc.
VariantToBString A handle to BString containing a string representation of VarSrc. The calling program is responsible for deallocating (calling StrFree) the returned BString.
VariantToCy A type(CURRENCY) structure resulting from the coercion of VarSrc.
VariantToDec A type(DECIMAL) structure resulting from the coercion of VarSrc.

 

All functions are called with the same parameters, including a variant (VarSrc) of any valid type. Arguments lcid and flags are used only if VarSrc is of type BString or contains a reference to an object. In all other cases, these two arguments are ignored.

Argument iRet

 

Indicates success or failure of the subroutine. The following codes can be returned in this argument:

 

 

Value returned in argument iRet Description
S_OK Success.
DISP_E_BADVARTYPE The source variant type or the value of vtType is not a valid type of variant.
DISP_E_OVERFLOW The data in VarSrc does not fit in the destination type.
DISP_E_TYPEMISMATCH VarSrc could not be coerced to the specified type.
E_INVALIDARG One of the arguments is invalid.
E_OUTOFMEMORY Memory could not be allocated for the conversion.

Examples

 

program VariantCastingExamples

 

!Demonstrate the use of some variant casting

!functions provided by f90VB

!Copyright 1999-2000, Canaima Software

!All rights reserved

 

use f90VBDefs

use f90VBBStrings

use f90VBVariants

implicit none

 

type(VARIANT)::vVar1

integer(HRESULT_KIND)::iRet

character(len=20)::TmpStr

integer(BSTRHNDL_KIND)::BStrHndl

 

vVar1=VariantCreate(VT_DECIMAL, '25.31')

 

!print the content of vVar1 converted to

!different Fortran intrinsic types

 

print *,'VariantToLogical(vVar1):',VariantToLogical(vVar1)

print *,'VariantToInteger(vVar1):',VariantToInteger(vVar1)

print *,'VariantToReal(vVar1):',VariantToReal(vVar1)

print *,'VariantToDouble(vVar1):',VariantToDouble(vVar1)

BStrHndl = VariantToBString(vVar1)

call StrCopy(BStrHndl,TmpStr)

print *,'VariantToBString(vVar1):',trim(TmpStr)

 

!release memory used by BSTR

call StrFree(BStrHndl)

 

!clear variant contents

call VariantClear(vVar1)

 

stop

end

Related Topics

 

For information about: See:
Changing the type of a variant VariantChangeType
Copying a variant VariantCopyInd, VariantCopy

 

 

 


VariantCat