none
pass value to vb.net constructor from vb6

Answers

  • Is it possible or not? Please stop wasting time if you cant help. you just going in circles
    It is not possible to create a COM constructor with a parameter - there is no such thing. Even though you are setting it as a reference, the COM object is created using CoCreateInstance - the reference mechanism just wraps that for you.   But according to your description that's not what you are doing: "...pass value to vb.net constructor" means that you are trying to construct .Net object that is part of your COM component, and that .Net object apparently has a constructor with parameters, and that's what you are trying to create.   Without the details of what happens when you try to do that it's not possible to know what the problem might be.   But since you have already created the .COM object successfully, it seems to me it is easiest to just create a method to pass the value to the new object after you create it using a method defined for the purpose.
    • Marked as answer by Me.Saqib Monday, April 24, 2017 2:46 PM
    Saturday, April 22, 2017 10:49 PM

All replies

  • Is there a way to pass value to vb.net constructor from vb6?

    If you want to pass some information from a VB6 application to a VB.Net application when it starts, you can use command line arguments.
    https://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs(v=vs.110).aspx

    'Constructor' usually refers to an object, and VB6 cannot create .Net objects.

    • Proposed as answer by Frank L. Smith Thursday, April 20, 2017 11:28 PM
    • Unproposed as answer by Me.Saqib Saturday, April 22, 2017 9:48 PM
    Thursday, April 20, 2017 10:44 PM
  • I have created some COM object in vb.net and then I have initialized them in VB6

    Dim s as object 

    set s = New Class1

    and it worked. The only thing here I cannot call parameterized constructor to pass value.

    Friday, April 21, 2017 8:11 PM
  • The only thing here I cannot call parameterized constructor to pass value.

    You will have to provide much more detail.  Does your class have the COMVisible attribute set?  Are you using a reference or a Declare?  Is the COM object set up to accept a parameter in the constructor? What happens when you pass a parameter (is there an error message, or is it ignored)?   How did you get it to work without  specifying the assembly name in the call to the constructor?

    Friday, April 21, 2017 9:48 PM
  •  

    Does your class have the COMVisible attribute set? 

    Answer: I dont have attribute set but I have checkbox checked under Properties/Compile "Register for COM interop" - I think it meant same COMVisible = true. I dont know.

    Are you using a reference or a Declare? 

    Answer: I m using vb.net class as a reference in VB6. Not using CreateObject.

    Is the COM object set up to accept a parameter in the constructor?

    Answer: NO

    What happens when you pass a parameter (is there an error message, or is it ignored)?  

    Answer: I couldnt make the value to pass from vb6, getting compile error in vb6

     How did you get it to work without  specifying the assembly name in the call to the constructor?

    Answer: I had to put Assemblyname.ClassName


    Friday, April 21, 2017 11:52 PM
  • Is the COM object set up to accept a parameter in the constructor?

    Answer: NO

    Then you won't be able to call the constructor with a parameter.  A workaround is to create a method (with argument) that sets the required variable, and call the method after you create the object.

    Saturday, April 22, 2017 12:42 AM
  • Sorry for wrong answer in above question.

    Yes ofcourse my com Class is setup to accept a parameter in constructor. This was the whole reason I started this thread. 

    How do I pass this parameter in vb6? 

    Saturday, April 22, 2017 7:41 PM
  • How do I pass this parameter in vb6? 

    What exactly is the error that is reported?  What is the type of the parameter, and what is the value you are passing?
    Saturday, April 22, 2017 9:21 PM
  • Is it possible or not? Please stop wasting time if you cant help. you just going in circles
    Saturday, April 22, 2017 9:51 PM
  • Is it possible or not? Please stop wasting time if you cant help. you just going in circles
    It is not possible to create a COM constructor with a parameter - there is no such thing. Even though you are setting it as a reference, the COM object is created using CoCreateInstance - the reference mechanism just wraps that for you.   But according to your description that's not what you are doing: "...pass value to vb.net constructor" means that you are trying to construct .Net object that is part of your COM component, and that .Net object apparently has a constructor with parameters, and that's what you are trying to create.   Without the details of what happens when you try to do that it's not possible to know what the problem might be.   But since you have already created the .COM object successfully, it seems to me it is easiest to just create a method to pass the value to the new object after you create it using a method defined for the purpose.
    • Marked as answer by Me.Saqib Monday, April 24, 2017 2:46 PM
    Saturday, April 22, 2017 10:49 PM
  • Is it possible or not? Please stop wasting time if you cant help. you just going in circles

    Maybe for others it is, they dig for information how to do it. 

    You try it with throwing a hammer in the air and hopes that it one day hits a nail and than start to blame others it is not hitting the nail.

    However, I've seen more trying to do this and those experiences don't give much hope.


    Success
    Cor

    Sunday, April 23, 2017 1:40 PM