Solved

Late binding

Posted on 2004-09-13
14
1,237 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 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