Hi all,
I am trying to covert a VB macro to C# code. Here is a macro recorded from ACCPAC 5.2
private Function Create_GL_Batch()
'This function creates a new batch entry
'It is recorded from the ACCPAC program
On Error GoTo errorHandler
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkCmpRW = Session.OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)
Dim mDBLinkSysRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkSysRW = Session.OpenDBLink(DBLINK_SYSTEM, DBLINK_FLG_READWRITE)
Dim GLBATCH1batch As AccpacCOMAPI.AccpacView
Dim GLBATCH1batchFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "GL0008", GLBATCH1batch
Set GLBATCH1batchFields = GLBATCH1batch.Fields
Dim GLBATCH1header As AccpacCOMAPI.AccpacView
Dim GLBATCH1headerFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "GL0006", GLBATCH1header
Set GLBATCH1headerFields = GLBATCH1header.Fields
Dim GLBATCH1detail As AccpacCOMAPI.AccpacView
Dim GLBATCH1detailFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "GL0010", GLBATCH1detail
Set GLBATCH1detailFields = GLBATCH1detail.Fields
GLBATCH1batch.Compose Array(GLBATCH1header)
GLBATCH1header.Compose Array(GLBATCH1batch, GLBATCH1detail)
GLBATCH1detail.Compose Array(GLBATCH1header)
GLBATCH1batch.Browse "((BATCHSTAT = ""1"" OR BATCHSTAT = ""6"" OR BATCHSTAT = ""9""))", 1
GLBATCH1batch.Init
GLBATCH1batch.Read
GLBATCH1headerFields("BTCHENTRY").PutWithoutVerification ("") ' Entry Number
GLBATCH1header.Browse "", 1
GLBATCH1header.Fetch
GLBATCH1header.Init
Create_GL_Batch = GLBATCH1headerFields("BATCHID").Value
Exit Function
errorHandler:
HandleError
Exit Function
End Function
This is what I changed. However it has a compile err on "Compose"
public void Create_GL_Batch()
{
try
{
AccpacCOMAPI.AccpacDBLink mDBLinkCmpRW ;//= new AccpacCOMAPI.AccpacDBLink() ;
mDBLinkCmpRW = Session.OpenDBLink (AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_COMPANY,AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE);
AccpacCOMAPI.AccpacDBLink mDBLinkSysRW;
mDBLinkSysRW = Session.OpenDBLink (AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_SYSTEM,AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE);
AccpacCOMAPI.AccpacView GLBATCH1batch;
AccpacCOMAPI.AccpacViewFields GLBATCH1batchFields;
mDBLinkCmpRW.OpenView ("GL0008", out GLBATCH1batch) ;
GLBATCH1batchFields = GLBATCH1batch.Fields ;
AccpacCOMAPI.AccpacView GLBATCH1header = new AccpacCOMAPI.AccpacViewClass() ;
AccpacCOMAPI.AccpacViewFields GLBATCH1headerFields;
mDBLinkCmpRW.OpenView ("GL0006", out GLBATCH1header);
GLBATCH1headerFields = GLBATCH1header.Fields;
AccpacCOMAPI.AccpacView GLBATCH1detail;
AccpacCOMAPI.AccpacViewFields GLBATCH1detailFields;
mDBLinkCmpRW.OpenView ("GL0010", out GLBATCH1detail);
GLBATCH1detailFields = GLBATCH1detail.Fields;
//This is the part with error.
//GLBATCH1batch.Compose (ref GLBATCH1header);
//GLBATCH1header.Compose (GLBATCH1batch, GLBATCH1detail);
//GLBATCH1detail.Compose (GLBATCH1header);
GLBATCH1batch.Browse ("((BATCHSTAT = \"1\" OR BATCHSTAT = \"6\" OR BATCHSTAT = \"9\"))",true);
GLBATCH1batch.Init();
GLBATCH1batch.Read();
//GLBATCH1headerFields.get_FieldByName("BTCHENTRY").PutWithoutVerification (ref null); // Entry Number
GLBATCH1header.Browse ("", true);
GLBATCH1header.Fetch();
GLBATCH1header.Init();
//Create_GL_Batch = GLBATCH1headerFields("BATCHID").Value;
}
catch (Exception exp)
{
throw exp ;
}
}
error:
D:\CUC\CUC\CUC\CUCData.cs(185): Argument '1': cannot convert from 'AccpacCOMAPI.AccpacView' to 'ref object'
D:\CUC\CUC\CUC\CUCData.cs(185): The best overloaded method match for 'AccpacCOMAPI.IAccpacView.Compose(ref object)' has some invalid arguments
I tried with or without "ref". Same error.
Anyone has some suggestions? Thanks
I am trying to covert a VB macro to C# code. Here is a macro recorded from ACCPAC 5.2
private Function Create_GL_Batch()
'This function creates a new batch entry
'It is recorded from the ACCPAC program
On Error GoTo errorHandler
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkCmpRW = Session.OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)
Dim mDBLinkSysRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkSysRW = Session.OpenDBLink(DBLINK_SYSTEM, DBLINK_FLG_READWRITE)
Dim GLBATCH1batch As AccpacCOMAPI.AccpacView
Dim GLBATCH1batchFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "GL0008", GLBATCH1batch
Set GLBATCH1batchFields = GLBATCH1batch.Fields
Dim GLBATCH1header As AccpacCOMAPI.AccpacView
Dim GLBATCH1headerFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "GL0006", GLBATCH1header
Set GLBATCH1headerFields = GLBATCH1header.Fields
Dim GLBATCH1detail As AccpacCOMAPI.AccpacView
Dim GLBATCH1detailFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "GL0010", GLBATCH1detail
Set GLBATCH1detailFields = GLBATCH1detail.Fields
GLBATCH1batch.Compose Array(GLBATCH1header)
GLBATCH1header.Compose Array(GLBATCH1batch, GLBATCH1detail)
GLBATCH1detail.Compose Array(GLBATCH1header)
GLBATCH1batch.Browse "((BATCHSTAT = ""1"" OR BATCHSTAT = ""6"" OR BATCHSTAT = ""9""))", 1
GLBATCH1batch.Init
GLBATCH1batch.Read
GLBATCH1headerFields("BTCHENTRY").PutWithoutVerification ("") ' Entry Number
GLBATCH1header.Browse "", 1
GLBATCH1header.Fetch
GLBATCH1header.Init
Create_GL_Batch = GLBATCH1headerFields("BATCHID").Value
Exit Function
errorHandler:
HandleError
Exit Function
End Function
This is what I changed. However it has a compile err on "Compose"
public void Create_GL_Batch()
{
try
{
AccpacCOMAPI.AccpacDBLink mDBLinkCmpRW ;//= new AccpacCOMAPI.AccpacDBLink() ;
mDBLinkCmpRW = Session.OpenDBLink (AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_COMPANY,AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE);
AccpacCOMAPI.AccpacDBLink mDBLinkSysRW;
mDBLinkSysRW = Session.OpenDBLink (AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_SYSTEM,AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE);
AccpacCOMAPI.AccpacView GLBATCH1batch;
AccpacCOMAPI.AccpacViewFields GLBATCH1batchFields;
mDBLinkCmpRW.OpenView ("GL0008", out GLBATCH1batch) ;
GLBATCH1batchFields = GLBATCH1batch.Fields ;
AccpacCOMAPI.AccpacView GLBATCH1header = new AccpacCOMAPI.AccpacViewClass() ;
AccpacCOMAPI.AccpacViewFields GLBATCH1headerFields;
mDBLinkCmpRW.OpenView ("GL0006", out GLBATCH1header);
GLBATCH1headerFields = GLBATCH1header.Fields;
AccpacCOMAPI.AccpacView GLBATCH1detail;
AccpacCOMAPI.AccpacViewFields GLBATCH1detailFields;
mDBLinkCmpRW.OpenView ("GL0010", out GLBATCH1detail);
GLBATCH1detailFields = GLBATCH1detail.Fields;
//This is the part with error.
//GLBATCH1batch.Compose (ref GLBATCH1header);
//GLBATCH1header.Compose (GLBATCH1batch, GLBATCH1detail);
//GLBATCH1detail.Compose (GLBATCH1header);
GLBATCH1batch.Browse ("((BATCHSTAT = \"1\" OR BATCHSTAT = \"6\" OR BATCHSTAT = \"9\"))",true);
GLBATCH1batch.Init();
GLBATCH1batch.Read();
//GLBATCH1headerFields.get_FieldByName("BTCHENTRY").PutWithoutVerification (ref null); // Entry Number
GLBATCH1header.Browse ("", true);
GLBATCH1header.Fetch();
GLBATCH1header.Init();
//Create_GL_Batch = GLBATCH1headerFields("BATCHID").Value;
}
catch (Exception exp)
{
throw exp ;
}
}
error:
D:\CUC\CUC\CUC\CUCData.cs(185): Argument '1': cannot convert from 'AccpacCOMAPI.AccpacView' to 'ref object'
D:\CUC\CUC\CUC\CUCData.cs(185): The best overloaded method match for 'AccpacCOMAPI.IAccpacView.Compose(ref object)' has some invalid arguments
I tried with or without "ref". Same error.
Anyone has some suggestions? Thanks