![]() |
|
||||||||||||||||||||||||
|
|
Using subroutine StrCopy (StrCopyExamples) StrCopy is the work-horse of the BStrings library. With StrCopy your Fortran program can easily convert a string from one type to the other. Below is a simple example demonstrating the some of the features of this subroutine: |
||||||||||||||||||||||||
Program StrCopyExamples
!Demonstrates several uses of subroutine StrCopy
!Copyright (C) 1999-2000, Canaima Software, Inc.
!All rights reserved
!load f90VB modules
use f90VBDefs
use f90VBBStrings
implicit none
!Declare two Bstrings
integer(BSTRHNDL_KIND):: BStrA, BStrB
!Declare a Fixed OLE String (integer vector)
integer(OLECHAR_KIND)::FxOLEStr(15)
!Declare a Fortran OLE String structure
type(OLESTRING)::OLEStr
!Declare a Fortran string
character(len=35)::FStr
!utility variables
integer(HRESULT_KIND)::iRet
integer::i
character(len=1024)::TmpFStr
!Create and initialize a new BString
call StrCopy('This is a BString example',BStrB,iRet)
if (iRet.eq.BSTRINGS_ERROR) then
print *,'Error creating BString'
else
call StrCopy(BStrB,TmpFStr)
print *,'A BString was created'
print *,'BString Length:',StrLenTrim(BStrB)
print *,'BString handle:',BStrB
print *,'BString content:', trim(TmpFStr)
endif
!Copy the first 10 characters of BStrB
!to a Fortran String
call StrCopy(BStrB,FStr,iRet,10)
!add some additional text to fortran string
if (iRet.eq.BSTRINGS_ERROR) then
print *,'Error copying BString to Fortran String'
else
FStr=trim(FStr)//' Fortran String example'
print *,''
print *,'BString copied to Fortran String'
print *,'Fortran String Length:',StrLenTrim(FStr)
print *,'Fortran String content:',trim(FStr)
endif
!create a Fortran OLE String with a large buffer
call StrCopy(FStr(1:8)//'not '//FStr(9:24),OLEStr, &
iRet,100)
if (iRet.eq.BSTRINGS_ERROR) then
print *,'Error creating Fortran OLE String'
else
call StrCopy(OLEStr,TmpFStr)
print *,''
print *,'Fortran OLE String Created'
print *,'OLE String Length:',StrLenTrim(OLEStr)
print *,'OLE String Buffer length:', StrLen(OLEStr)
print *,'OLE String content:',trim(TmpFStr)
print *,'Fortran OLE String structure:'
print *,'String handle:',OLEStr%StrHndl
print *,'First 5 characters:', (OLEStr%Str(i),i=1,5)
print *,'First 5 characters in ascii:', &
(achar(OLEStr%Str(i)),i=1,5)
endif
!Create a new BString from a Fortran OLE String
call StrCopy(OLEStr,BStrA,iRet)
if (iRet.eq.BSTRINGS_ERROR) then
print *,'Error creating BString'
else
call StrCopy(BstrA,TmpFStr)
print *,''
print *,'A BString was created'
print *,'BString Length:',StrLenTrim(BStrA)
print *,'BString buffer length:',StrLen(BStrA)
print *,'BString handle:',BStrA
print *,'BString content:', trim(TmpFStr)
endif
!Change the content of a Bstring and
!force allocation of a large buffer
call StrCopy(BStrA,BStrB,iRet,150)
if (iRet.eq.BSTRINGS_ERROR) then
print *,'Error creating BString'
else
call StrCopy(BstrB,TmpFStr)
print *,''
print *,'A BString was created'
print *,'BString Length:',StrLenTrim(BStrB)
print *,'BString buffer length:',StrLen(BStrB)
print *,'BString handle:',BStrB
print *,'BString content:', trim(TmpFStr)
endif
!Produces an error because Fixed OLE String is not
!large enough to hold all characters in Fortran String
print *,''
print *,'FxOLEStr is too small to accept FStr'
call StrCopy(FStr,FxOLEStr,iRet)
if (iRet.eq.BSTRINGS_ERROR) then
print *,'Error creating BString'
endif
print *,'Copy only the first 4 characters of FStr'
call StrCopy(FStr,FxOLEStr,iRet,4)
if (iRet.eq.BSTRINGS_ERROR) then
print *,'Error creating BString'
else
call StrCopy(FxOLEStr,TmpFStr)
print *,'A Fixed OLE String was created'
print *,'Fixed OLE String Length:', &
StrLenTrim(FxOLEStr)
print *,'Fixed OLE buffer length:', &
StrLen(FxOLEStr)
print *,'Fixed OLE content:', trim(TmpFStr)
endif
!release memory used by dynamic f90VB strings
call StrFree(BstrA)
call StrFree(BstrB)
call StrFree(OLEStr)
stop
end
|
|||||||||||||||||||||||||
|
Copyright
© 1998-2000 Canaima Software
For questions regarding this site, send an e-mail to webmaster@canaimasoft.com |
|||||||||||||||||||||||||