Results 1 to 6 of 6

Thread: [RESOLVED] Issue pssing data between VB 6.0 and .NET

  1. #1

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,960

    Resolved [RESOLVED] Issue pssing data between VB 6.0 and .NET

    I have a VB 6.0/.NET program combination that I'm trying to return data back to VB 6.0. I'm pretty sure I'm missing something simple.

    This is the VB 6.0 program:

    Private Sub cmdTestIt_Click()

    Dim strX As String
    strX = "1234"

    Dim mImageMainNet As New ImageMainNet.Main
    mImageMainNet.TestIt (strX)

    MsgBox strX

    End Sub
    This is the .NET program:

    <ComClass(Main.ClassID, Main.InterfaceID, Main.EventsID)>
    Public Class Main

    Public Sub TestIt(ByRef strX As String)
    strX = "Test"
    End Sub

    End Class
    I'm expecting the test "Test" to come back but it remains "1234". I know I'm hitting the .NET program via stepping through the code. I don't see what I'm missing. I thought ByRef would do it. Any suggestions?
    Attached Images Attached Images  
    Please remember next time...elections matter!

  2. #2
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    479

    Re: Issue pssing data between VB 6.0 and .NET

    Have you tried changing ByRef to ByVal?

    You could also use a Function instead of Sub and return strX from TestIt.

    I haven't tested any of this but it is where I would start.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,824

    Re: Issue pssing data between VB 6.0 and .NET

    ByRef would be right. If you were to pass it ByVal, it should behave the way it is behaving. However, .NET and VB6 changed the default passing behavior. In .NET it is ByVal, which means that in VB6 it is ByRef (I don't remember, I just remember that the two languages swapped the default).

    I've certainly never tried this, though.
    My usual boring signature: Nothing

  4. #4
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    479

    Re: Issue pssing data between VB 6.0 and .NET

    That's what I get for typing and reading too quickly and not thinking it through, sorry.

    TysonLPrice, does TestIt see the "1234" in strX before strX is reset to "Test"?

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    12,086

    Re: Issue pssing data between VB 6.0 and .NET

    I don't understand why your .NET method is a sub routine. It sounds like you expect to pass a value from your VB6 application, have your VB.NET application transform the value, and then the VB.NET application returns the transformed value. I don't have much experience with inter-application communication like this, but I'd expect something like this:
    Code:
    Public Function TestIt(ByVal strX As String) As String
        strX = "Test"
        Return strX
    End Function
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,960

    Re: Issue pssing data between VB 6.0 and .NET

    I tried a half a dozen times all day to try and post I made it a function and it works. Time out after time out....

    Thanks to the responders
    Last edited by TysonLPrice; Mar 14th, 2025 at 06:07 PM.
    Please remember next time...elections matter!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width