Solved

Late binding

Posted on 2004-09-13
14
1,243 Views
Last Modified: 2012-02-23
Hi!

I have the following code that needs to be translated into C#(no problems) and used with late binding(???)
A reference to gbaapi.exe is added in the project.

      Dim oGBA As Object
      Dim RetValue
      'Creates the GBA object
      Set oGBA = CreateObject("GBAAPI.GBA")

      'Specifies the data location of the chosen client
      RetValue = oGBA.SetClientPath("c:\program files\mamut\data\client\000\001")
      If RetValue = 0 Then
          Response = MsgBox("The path to the client data location is incorrect.", 0, "MAMUT API")
      End If

      'Adds the contact object to the GBA object
      Dim oContact
      Set oContact = oGBA.CreateContactObject()
      If TypeName(oContact) <> "Object" Then
              Response = MsgBox("An error occurred during the creation of the Contact object.", 0, "MAMUT API")
      End If

      'Create a new contact
      RetValue = oContact.CreateNew()
      If RetValue = 0 Then
          Response = MsgBox("An error occurred during creation of new contact.", 0, "MAMUT API")
      End If

      'Make changes to a contact (after it is retrieved/created)
      oContact.ContName = "Mamut Ltd"
      oContact.Street = "90 Long Acre"
      oContact.City = "London"
      oContact.Zipcode = "WC2E 9RZ"
      oContact.Data56 = 1

      'Save a contact
      RetValue = oContact.Save()
      If RetValue = 0 Then
          Response = MsgBox("An error occurred during saving of contact.", 0, "MAMUT API")
      End If


I tried this:
      public class Faktura
      {
            public bool CreateFaktura()
            {
                  gbaapi.gba GBA = new gbaapi.gba();
                  if(GBA.setclientpath(@"\\SERVER\Mamut\Data\Client\000\001").ToString()!="0")
                  {      
                        gbaapi.contactClass oContact = (gbaapi.contactClass)GBA.createcontactobject();
                        int RetValue = oContact.createnew();
                        if(RetValue==0)
                        {
                              oContact.contname = "Mamut Ltd";
                              oContact.street = "90 Long Acre";
                              oContact.city = "London";
                              oContact.zipcode = "WC2E 9RZ";
                              oContact.data56 = 1;

                               oContact.save()
                        
                              return true;
                        }
                        else
                              return false;
                  }
                  else
                        return false;
            }
      }

But I keep getting this:
No overload for method 'createnew' takes '0' arguments

public virtual new System.Object createnew ( System.Int32 lnContid )
Member of gbaapi.contactClass

The manual says nothing about create new needs an argument:
Creates a new contact. All properties of the Contact object are now blank (default from the client), except Contid to which the next available number in the number series is assigned. If the requested customer number is already in use, the next available number will be assigned.      

Returns the value 0 if an error occurs; otherwise returns the value 1.

What am I doing wrong?
0
Comment
Question by:aleborg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
14 Comments
 
LVL 14

Accepted Solution

by:
AvonWyss earned 500 total points
ID: 12042757
Try
int RetValue = oContact.createnew(1);

According to the manual, this should work, since "If the requested customer number is already in use, the next available number will be assigned." - so if customer 1 already exists, it will skip and use the next available.

Note that the late-binding interface (IDispatch, which old VB, VBScript etc. used) may be supporting default values or optional parameters, while the normal interface does not (which C# uses).
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12043263
aleborg, thank you for grading the question. But may I ask you to explain what I could have done better to get a higher grade?
0
 

Author Comment

by:aleborg
ID: 12044113
nothing, I was in a hurry and just clicked, sorry :)
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:aleborg
ID: 12044370
It worked but now I get the error The given transformation is invalid on this row:
gbaapi.contactClass oContact = (gbaapi.contactClass)GBA.createcontactobject();
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12044409
You get this at runtime, not at compile time, right?
0
 

Author Comment

by:aleborg
ID: 12044491
yes
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12044732
What does the manual say about the createcontactobject() method?
0
 

Author Comment

by:aleborg
ID: 12045063
Nothing, but the object browser says:
public virtual new System.Object createcontactobject (  )
    Member of gbaapi.gbaClass

so I tried:
gbaapi.contactClass oContact = (gbaapi.gbaClass)GBA.createcontactobject();
and I get:
Cannot implicitly convert type 'gbaapi.gbaClass' to 'gbaapi.contactClass'

In the VB example they do this:

     Dim oContact
     Set oContact = oGBA.CreateContactObject()
     If TypeName(oContact) <> "Object" Then
             Response = MsgBox("An error occurred during the creation of the Contact object.", 0, "MAMUT API")
     End If

     'Create a new contact
     RetValue = oContact.CreateNew()
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12053719
Apparently, oGBA.CreateContactObject() does not return a contact but rather some object where you need to call CreateNew() to get the actual contact. Could that be?
0
 

Author Comment

by:aleborg
ID: 12054007
That's correct I think, oGBA.CreateContactObject() returns an object where I need to call CreateNew()  to CREATE a new contact but how?
I've tried
object oContact = oGBA.CreateContactObject();
but it don't work
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12054082
Do you have an overview of the different classes and interfaces of this library? Use the Class Explorer to see the different types, and see if one of these has a method called CreateNew().
0
 

Author Comment

by:aleborg
ID: 12054421
gbaapi.contactClass has it:
public virtual new System.Object createnew ( System.Int32 lnContid )
Member of gbaapi.contactClass
That is why I did this:
gbaapi.contactClass oContact = (gbaapi.gbaClass)GBA.createcontactobject();
0
 

Expert Comment

by:cewens
ID: 37637696
i have a problem where i am using dynamic to add a order. i have wcf rest service with the api. but i run the rest service in debug mode it works perfectly but when i deploy it to iis it does not work i get an error in initializing the order. any ideas
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question