Compared my original code with yours and added three lines as shown below and now works fine.
These same lines were not required in the equivalent VB6 code which did not require an Answer object.
VBx is certainly very forgiving, but I think that maybe encourages careless coding.
Thanks again
Ian B
~~~~~
#REGISTER NONE
#COMPILE EXE
#DEBUG ERROR ON
#TOOLS ON
OPTION EXPLICIT
#INCLUDE "HDAns.inc"
#INCLUDE "HDAnsColl.inc
FUNCTION PBMAIN () AS LONG
ON ERROR GOTO ERRORTRAP
DIM vFileType AS VARIANT
DIM vVarName AS VARIANT
DIM vVarValue AS VARIANT
DIM vAnsFile AS VARIANT
DIM vVarType AS VARIANT
DIM lVarType AS LONG
DIM oHDAc AS DISPATCH
DIM oHDAns AS DISPATCH
DIM vVarAns AS VARIANT
lVarType = 1
vVarType = BYREF lVarType
vFileType = 2
vAnsFile = "C:\Temp\12345678.anx"
vVarName = "FirstName"
LET oHDAC = NEW DISPATCH IN "HotDocs.AnswerCollection"
LET oHDAns = NEW DISPATCH IN "HotDocs.Answer" '<<< ADDED
IF ISOBJECT(oHDAC) = 0 THEN
MSGBOX ("Stuffed Answer collection")
EXIT FUNCTION
END IF
IF ISOBJECT(oHDAns) = 0 THEN
MSGBOX ("Stuffed Answer ")
EXIT FUNCTION
END IF
OBJECT LET oHDAc.FileFormat = vFileType
OBJECT CALL oHDAc.Create(vAnsFile)
OBJECT CALL oHDAc.Item(vVarName, vVarType) TO vVarValue
oHDAns = vVarValue '<<< ADDED
OBJECT GET oHDAns.Value TO vVarValue '<<< ADDED
MSGBOX VARIANT$(vVarValue)
ResumePoint:
SET oHDAc=NOTHING
SET oHDAns = NOTHING
EXIT FUNCTION
ERRORTRAP:
MSGBOX USING$ ("Error # &", ERR, ERROR$(ERR))
RESUME ResumePoint
END FUNCTION
Announcement
Collapse
No announcement yet.
COM Interface Variant requirement
Collapse
X
-
Just found a similar result.
I used your code with HD2006 and it works fine.
This proves the obvious - your coding ability far exceeds mine!!
I'll progress using your code as a basis if thats OK with you.
Regards
Ian B
Leave a comment:
-
Actually, I just downloaded the demo to try it out.
It works just fine even when I replaced the 2008 declare for the Item method
with your 2006 declare(used variant instead of long for varType).
Leave a comment:
-
Dominic
Thankyou for your code which makes me feel much less lonely (someone else drives HotDocs from PB) and is a great example which I can build on.
Our client is using HotDocs 2006 so I will experiment amongst the different releases.
As the subject has moved away from PB towards HotDocs I wont clutter the threads with Hotdocs items but may contact you privately with the version testing results.
Thanks again
Ian B
Leave a comment:
-
You might want to upgrade to the latest version of HotDocs. For example, the code shown below
works with HotDocs 2008 SR1a.
Code:LOCAL szText AS ASCIIZ * 2048 LOCAL oHotDocs AS HotDocsApplication LOCAL oAnsCollection AS HotDocsAnswerCollection LOCAL oAnswer AS HotDocsAnswer LOCAL vVarType AS VARIANT LOCAL vFileFormat AS VARIANT LOCAL vFile AS VARIANT LOCAL vVarName AS VARIANT LOCAL vVarValue AS VARIANT LOCAL vIndex AS VARIANT LOCAL cItems AS LONG LOCAL iItem AS LONG SET oAnsCollection = NEW HotDocsAnswerCollection IN $PROGID_HOTDOCSANSWERCOLLECTION65 IF ISOBJECT(oAnsCollection) THEN ' Open answer file and display names and values vFile = "F:\Support\HotDocs\Bin\test.anx" OBJECT CALL oAnsCollection.Create(vFile) OBJECT GET oAnsCollection.Title TO vVarValue MSGBOX VARIANT$(vVarValue) OBJECT GET oAnsCollection.Count TO vVarValue cItems = VARIANT#(vVarValue) WHILE iItem < cItems vIndex = iItem OBJECT CALL oAnsCollection.Item(vIndex) TO vVarValue oAnswer = vVarValue IF ISOBJECT(oAnswer) THEN OBJECT GET oAnswer.Name TO vVarValue szText = "Name: " + VARIANT$(vVarValue) + $CRLF OBJECT GET oAnswer.Value TO vVarValue szText = szText + "Value: " + VARIANT$(vVarValue) MSGBOX szText END IF INCR iItem WEND ' Open a specific name and display its value vVarType = %HDVARTYPE_HD_TEXTTYPE vVarName = "Author Full Name" OBJECT CALL oAnsCollection.Item(vVarName, vVarType) TO vVarValue oAnswer = vVarValue IF ISOBJECT(oAnswer) THEN OBJECT GET oAnswer.Value TO vVarValue MSGBOX VARIANT$(vVarValue) END IF END IF
HotDocs 2006 SP1
Code:Member Call Item<&H00000000>(in index As Variant<&H00000000>, optional inout varType As Variant) As HotDocsAnswer
Code:MEMBER CALL Item<&H00000000>(IN index AS VARIANT<&H00000000>, OPTIONAL INOUT varType AS LONG<&H00000001>) AS HotDocsAnswer
Leave a comment:
-
Thanks again José.
The problem remains, which makes me think that I have more than 1 issue. I tried using the Index parameter which is type independant, and still cannot get a valid response. I ran the type library through your TypeLib Browser and show results below. I note the output is also byRef.
I will start the project over using a different approach. I note the inout enables interrogation for the type and so you have given me new avenues to explore. May take a day or so but I'll report back.
Ian B
' ****************************************************************************************
' Item method
' Interface name = _AnswerCollection
' Retrieve a specific answer. Index can be numeric (position) or string (variable name).
' VTable offset = 44 [&H2C]
' DispID = 0 [&H00000000]
' ****************************************************************************************
FUNCTION HotDocs_AnswerCollection_Item ( _
BYVAL pthis AS DWORD PTR _ ' %VT_DISPATCH <dispinterface>
, BYVAL index AS VARIANT _ ' %VT_VARIANT <VARIANT> [in]
, BYREF varType AS LONG _ ' *HDVARTYPE <enum> [opt] [in] [out]
, BYREF pItem AS DWORD _ ' **_Answer <dispinterface> [out]
) AS LONG ' %VT_HRESULT <LONG>
LOCAL HRESULT AS LONG
CALL DWORD @@pthis[11] USING HotDocs_AnswerCollection_Item(pthis, index, varType, pItem) TO HRESULT
FUNCTION = HRESULT
END FUNCTION
Leave a comment:
-
Member Call Item<&H00000000>(in index As Variant<&H00000000>, optional inout varType As Variant) As HotDocsAnswer '<<<< Line in question
Code:' Make sure lType is not a register variable #REGISTER NONE DIM lType AS LONG DIM vVarType AS VARIANT lType = 1 vVarType = BYREF lType
Leave a comment:
-
Thanks for the suggestion José. I tried this with no luck. I suspect the problem is with the COM Object.
There are quite a large number of other functions available with this object, none of which get fussed about variants.
I show below the Include file, in case it shows something useful. It is contradictory, in that it indicates it does want a variant in the "Item" function. I note that this same function does not use a enumHotDocsxxx.
Here is a line from another function in the same object, which is also referring to the variable type.
~~~
Member Call Create<&H00000009>(in ansName As String<&H00000000>, in valType As enumHotDocsHDVARTYPE<&H00000001>)
I suspect this may be involved in the problem.
TIA
Ian B
~~~~~~~~~
' ------------------------------------------------------------
' Library Name: HotDocs 2006 Type Library 6.4
' Library File: D:\PROGRA~1\HOTDOC~1\hotdocs6.exe
' ------------------------------------------------------------
' Version Info:
' -------------
' Company Name: Matthew Bender & Company, Inc., a member of the LexisNexis Group.
' File Description: HotDocs 2006 SP1
' File Version: 6.4.0.170
' Internal Name: HOTDOCS6.EXE
' Legal Copyright: Copyright © 2006 Matthew Bender & Company, Inc., a member of the LexisNexis Group. All rights reserved.
' Legal Trademarks: HotDocs® is a registered trademark of Matthew Bender & Company, Inc., a member of the LexisNexis Group.
' Original Filename: HOTDOCS6.EXE
' Product Name: HotDocs
' Product Version: 6.4.0.170
' ------------------------------------------------------------
' ProgID: HotDocs.AnswerCollection.6
' Interface Name: HotDocsAnswerCollection
'
' Interface Prefix: HotDocs
' ------------------------------------------------------------
$PROGID_HotDocsAnswerCollection6 = "HotDocs.AnswerCollection.6"
Interface Dispatch HotDocsAnswerCollection
Member Get Count<&H00000001>() As Long
Member Call Close<&H00000002>()
Member Call UploadAnswerCollection<&H00000003>(in url As String<&H00000000>, in format As enumHotDocsHDANSWERUPLOADFORMAT<&H00000001>)
Member Call Add<&H00000004>(in newAnswer As HotDocsAnswer<&H00000000>)
Member Call Item<&H00000000>(in index As Variant<&H00000000>, optional inout varType As Variant) As HotDocsAnswer '<<<< Line in question
Member Get FileName<&H00000006>() As String
Member Get FileFormat<&H00000007>() As enumHotDocsHDAFFORMAT
Member Let FileFormat<&H00000007>() 'Parameter Type As enumHotDocsHDAFFORMAT
Member Call Overlay<&H00000008>(in overlayFileName As String<&H00000000>)
Member Get DefaultAnswerFile<&H00000009>() As String
Member Let DefaultAnswerFile<&H00000009>() 'Parameter Type As String
Member Call Create<&H0000000A>(optional in answerFileName As String<&H00000000>)
Member Call Save<&H0000000B>(optional in answerFileName As String<&H00000000>)
Member Get Application<&H0000000C>() As HotDocsApplication2
Member Get Title<&H00000064>() As String
Member Let Title<&H00000064>() 'Parameter Type As String
Member Get Description<&H00000065>() As String
Member Let Description<&H00000065>() 'Parameter Type As String
Member Get Modified<&H00000066>() As Long
Member Get XML<&H00000067>() As String
End Interface
Leave a comment:
-
If the VarType is a LONG value, then try vVarType = 1 AS LONG. Sometimes, the called method or property checks the type of the variant.
Leave a comment:
-
Thank you for your interest Edwin.
Here is simplified code, based on the many examples in this forum and help files. If there is a more elegant technique I would be glad for any pointers.
As long as vVarType is passed as a Variant the function compiles but returns an "undefined" answer. VB6 will compile but gives a run time error, argument type mismatch.
~~~~~~~~~
#COMPILE EXE
#DEBUG ERROR ON
#TOOLS ON
OPTION EXPLICIT
#INCLUDE "HDAns.inc"
#INCLUDE "HDAnsColl.inc
FUNCTION PBMAIN () AS LONG
ON ERROR GOTO ERRORTRAP
DIM vFileType AS VARIANT
DIM vVarName AS VARIANT
DIM vVarValue AS VARIANT
DIM vAnsFile AS VARIANT
DIM vVarType AS VARIANT
DIM oHDAc AS DISPATCH
DIM oHDAns AS DISPATCH
DIM vVarAns AS VARIANT
vVarType = 1
vFileType = 2
vAnsFile = "C:\Temp\5577.anx"
vVarName = "Name"
LET oHDAC = NEW DISPATCH IN "HotDocs.AnswerCollection"
IF ISOBJECT(oHDAC) = 0 THEN
MSGBOX ("Stuffed Answer collection")
EXIT FUNCTION
END IF
OBJECT LET oHDAc.FileFormat = vFileType
OBJECT CALL oHDAc.Create(vAnsFile)
OBJECT CALL oHDAc.Item(vVarName,vVarType) TO vVarValue '<<<< Line of failure
MSGBOX(VARIANT$(vVarValue))
ResumePoint:
EXIT FUNCTION
ERRORTRAP:
MSGBOX USING$ ("Error # &", ERR, ERROR$(ERR))
RESUME ResumePoint
END FUNCTION
Leave a comment:
-
COM Interface Variant requirement
I am converting an application from VB6 to PB.
One major task is to interface to a COM object using Includes generated with PB Com browser.
In one particular function, the COM interface refuses to accept a VARIANT parameter, rather, requiring a LONG parameter.
IN VB6 this is not a problem, but it seems insurmountable in PB.
I'm a very new PB person so forgive me if there is an obvious work around.
Maybe I need to be talking to the COM provider.
TIA
Ian BTags: None
Leave a comment: