?
Solved

Late binding

Posted on 2004-09-13
14
Medium Priority
?
1,255 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 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