|
发表于 2011-2-15 10:04:18
|
显示全部楼层
执行用友提供的VB API代码第5步:调用API,代码是"If u8apiBroker.InvokeApi() = False Then",出现错误"Object reference not set to an instance of an object未将对象引用到对象的实例",这是为什么呢?高人啊,请解答一下,万分感激! 以下是全部代码:
'[弃审采购到货单]调用示例
'添加对U8API框架类库引用(在U8SOFT\UFMOM\U8APIFramework目录):
'UFIDA.U8.MomServiceCommon.tlb
'UFIDA.U8.U8MOMAPIFramework.tlb
'UFIDA.U8.U8APIFramework.tlb
'添加Microsoft XML v3.0引用
Option Explicit
Public Sub CallU8Api()
On Error GoTo ErrHandler
'第一步:构造u8login对象并登陆
'如果当前环境中有login对象则可以省去第一步
Dim ologin As Object
Set ologin = CreateObject("U8Login.clsLogin")
If Not ologin.login("AS", "(default)@001", "2008", "demo", "", "2008-7-8", "localhost") Then
MsgBox ologin.ShareString
Else
'第二步:构造环境上下文对象,传入login,并按需设置其它上下文参数
Dim u8EnvCtx As New U8EnvContext
Set u8EnvCtx.U8Login = ologin
'采购所有接口均支持内部独立事务和外部事务,默认内部事务
'如果是外部事务,则需要传递ADO.Connection对象,并将IsIndependenceTransaction设置为false
'Dim bizDbConn As New ADO.Connection
'Set u8EnvCtx.BizDbConnection = bizDbConn
'u8EnvCtx.IsIndependenceTransaction = false
'设置上下文参数
u8EnvCtx.SetApiContext "VoucherType", "上下文值" '上下文数据类型:int,含义:单据类型, 采购到货单 2
u8EnvCtx.SetApiContext "bPositive", "上下文值" '上下文数据类型:bool,含义:红蓝标识:True,蓝字;False,红字
u8EnvCtx.SetApiContext "sBillType", "上下文值" '上下文数据类型:string,含义:到货单类型, 到货单 0 退货单 1
u8EnvCtx.SetApiContext "sBusType", "上下文值" '上下文数据类型:string,含义:业务类型:普通采购,直运采购,受托代销
'第三步:构造ApiBroker对象,调用Connect,传入Api的地址标识(Url),传入上下文
Dim u8apiBroker As New U8ApiComBroker
u8apiBroker.Connect "U8API/ArrivedGoods/CancelconfirmArr", u8EnvCtx
'第四步:API参数赋值
'给BO表头参数DomHead赋值,此BO参数的业务类型为到货单,属表头参数。BO参数均按引用传递
'提示:给BO表头参数DomHead赋值有两种方法
'方法一是直接传入MSXML2.DOMDocument对象
'Dim DomHead As New MSXML2.DOMDocument
'u8apiBroker.AssignNormalValue "DomHead", DomHead
'方法二是构造BusinessObject对象,具体方法如下:
Dim DomHead As BusinessObject
Set DomHead = u8apiBroker.GetBoParam("DomHead")
DomHead.RowCount = 1 '设置BO对象(表头)行数,只能为一行
'给BO对象(表头)的字段赋值,值可以是真实类型,也可以是无类型字符串
'****************************** 以下是必输字段 *****************************
DomHead(0).SetValue "id","字段值" '主关键字段,Integer类型
DomHead(0).SetValue "cbustype","字段值" '业务类型,Integer类型
DomHead(0).SetValue "ccode","字段值" '单据号,String类型
DomHead(0).SetValue "ddate","字段值" '日期,Date类型
DomHead(0).SetValue "cvenabbname","字段值" '供应商,String类型
DomHead(0).SetValue "cdepname","字段值" '部门,String类型
DomHead(0).SetValue "cexch_name","字段值" '币种,String类型
DomHead(0).SetValue "iexchrate","字段值" '汇率,Double类型
'***************************** 以下是非必输字段 ****************************
DomHead(0).SetValue "ipresent","字段值" '现存量,String类型
DomHead(0).SetValue "cmaketime","字段值" '制单时间,Date类型
DomHead(0).SetValue "cmodifytime","字段值" '修改时间,Date类型
DomHead(0).SetValue "cmodifydate","字段值" '修改日期,Date类型
DomHead(0).SetValue "creviser","字段值" '修改人,String类型
DomHead(0).SetValue "caudittime","字段值" '审核时间,Date类型
DomHead(0).SetValue "cauditdate","字段值" '审核日期,Date类型
DomHead(0).SetValue "cptname","字段值" '采购类型,String类型
DomHead(0).SetValue "ccloser","字段值" '关闭人,String类型
DomHead(0).SetValue "iverifystateex","字段值" '审核状态,String类型
DomHead(0).SetValue "ireturncount","字段值" '打回次数,String类型
DomHead(0).SetValue "iswfcontrolled","字段值" '是否启用工作流,String类型
DomHead(0).SetValue "cpersonname","字段值" '业 务 员,String类型
DomHead(0).SetValue "cscname","字段值" '运输方式,String类型
DomHead(0).SetValue "itaxrate","字段值" '税率,Double类型
DomHead(0).SetValue "cmemo","字段值" '备注,String类型
DomHead(0).SetValue "cmaker","字段值" '制单人,String类型
DomHead(0).SetValue "ivtid","字段值" '单据模版号,Integer类型
DomHead(0).SetValue "cverifier","字段值" '审核人,String类型
DomHead(0).SetValue "bnegative","字段值" '负发票标志,String类型
DomHead(0).SetValue "cvencode","字段值" '供货单位编号,String类型
DomHead(0).SetValue "cdepcode","字段值" '部门编号,String类型
DomHead(0).SetValue "cptcode","字段值" '采购类型编码,String类型
DomHead(0).SetValue "cpaycode","字段值" '付款条件编码,String类型
DomHead(0).SetValue "cpersoncode","字段值" '职员编号,String类型
DomHead(0).SetValue "ufts","字段值" '时间戳,String类型
DomHead(0).SetValue "cpayname","字段值" '付款条件,String类型
DomHead(0).SetValue "csccode","字段值" '运输方式编码,String类型
DomHead(0).SetValue "cdefine1","字段值" '表头自定义项1,String类型
DomHead(0).SetValue "cdefine2","字段值" '表头自定义项2,String类型
DomHead(0).SetValue "cdefine3","字段值" '表头自定义项3,String类型
DomHead(0).SetValue "cdefine4","字段值" '表头自定义项4,Date类型
DomHead(0).SetValue "cdefine5","字段值" '表头自定义项5,Integer类型
DomHead(0).SetValue "cdefine6","字段值" '表头自定义项6,Date类型
DomHead(0).SetValue "cdefine7","字段值" '表头自定义项7,Double类型
DomHead(0).SetValue "cdefine8","字段值" '表头自定义项8,String类型
DomHead(0).SetValue "cdefine9","字段值" '表头自定义项9,String类型
DomHead(0).SetValue "cdefine10","字段值" '表头自定义项10,String类型
DomHead(0).SetValue "cdefine11","字段值" '表头自定义项11,String类型
DomHead(0).SetValue "cdefine12","字段值" '表头自定义项12,String类型
DomHead(0).SetValue "cdefine13","字段值" '表头自定义项13,String类型
DomHead(0).SetValue "cdefine14","字段值" '表头自定义项14,String类型
DomHead(0).SetValue "cdefine15","字段值" '表头自定义项15,Integer类型
DomHead(0).SetValue "cdefine16","字段值" '表头自定义项16,Double类型
DomHead(0).SetValue "cvendefine1","字段值" '供应商自定义项1,String类型
DomHead(0).SetValue "cvendefine2","字段值" '供应商自定义项2,String类型
DomHead(0).SetValue "cvendefine3","字段值" '供应商自定义项3,String类型
DomHead(0).SetValue "cvendefine4","字段值" '供应商自定义项4,String类型
DomHead(0).SetValue "cvendefine5","字段值" '供应商自定义项5,String类型
DomHead(0).SetValue "cvendefine6","字段值" '供应商自定义项6,String类型
DomHead(0).SetValue "cvendefine7","字段值" '供应商自定义项7,String类型
DomHead(0).SetValue "cvendefine8","字段值" '供应商自定义项8,String类型
DomHead(0).SetValue "cvendefine9","字段值" '供应商自定义项9,String类型
DomHead(0).SetValue "cvendefine10","字段值" '供应商自定义项10,String类型
DomHead(0).SetValue "cvendefine11","字段值" '供应商自定义项11,String类型
DomHead(0).SetValue "cvendefine12","字段值" '供应商自定义项12,String类型
DomHead(0).SetValue "cvendefine13","字段值" '供应商自定义项13,String类型
DomHead(0).SetValue "cvendefine14","字段值" '供应商自定义项14,String类型
DomHead(0).SetValue "cvendefine15","字段值" '供应商自定义项15,String类型
DomHead(0).SetValue "cvendefine16","字段值" '供应商自定义项16,String类型
DomHead(0).SetValue "idiscounttaxtype","字段值" '扣税类别,Integer类型
DomHead(0).SetValue "ibilltype","字段值" '单据类型,Integer类型
DomHead(0).SetValue "cvenpuomprotocol","字段值" '收付款协议编码,String类型
DomHead(0).SetValue "cvenpuomprotocolname","字段值" '收付款协议名称,String类型
'第五步:调用API
If u8apiBroker.InvokeApi() = False Then
'第六步:错误处理
MsgBox u8apiBroker.GetLastError()
If u8apiBroker.ErrorType = ExceptionType_Business Then
'处理API业务错误
ElseIf u8apiBroker.ErrorType = ExceptionType_System Then
'处理系统错误
End If
Else
'第七步:获取返回结果
'获取返回值
'获取普通返回值。此返回值数据类型为String,此参数按值传递,表示错误描述:空,正确;非空,错误
Dim result As String
result = CStr(u8apiBroker.GetReturnValue())
End If
'结束本次调用,释放API资源
u8apiBroker.Disconnect
Set u8apiBroker = Nothing
End If
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub |
|