Solved

Late binding

Posted on 2004-09-13
14
1,207 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
  • 6
  • 6
14 Comments
 
LVL 14

Accepted Solution

by:
AvonWyss earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
nothing, I was in a hurry and just clicked, sorry :)
0
 

Author Comment

by:aleborg
Comment Utility
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
Comment Utility
You get this at runtime, not at compile time, right?
0
 

Author Comment

by:aleborg
Comment Utility
yes
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 14

Expert Comment

by:AvonWyss
Comment Utility
What does the manual say about the createcontactobject() method?
0
 

Author Comment

by:aleborg
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now