Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2005, 03:50 PM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing data from VBA to VB.NET

I'm calling a dll writtten in VB.NET from an Access 2003 app.
I need to pass about 50 data fields to the dll. Any suggestions on the best way to do this - short of having 50 parms?
Thanks.

 
Old February 2nd, 2005, 05:55 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Expose your class to com, and for the parameter create a new class that is also exposed to com but implements the IList interface. I successfully used the following code in an assembly that was exposed to COM:

Code:
Imports System.Runtime.InteropServices

Public Interface IClass1
    Function Concater(ByVal strings As Items) As String
End Interface

<ClassInterface(ClassInterfaceType.None)> _
Public Class Class1
    Implements IClass1
    Public Function Concater(ByVal strings As Items) As String Implements IClass1.Concater
        Dim counter As Integer
        Dim sb As New Text.StringBuilder
        Dim str As String
        For Each str In strings
            sb.Append(str)
        Next
        Return sb.ToString
    End Function
End Class

<ClassInterface(ClassInterfaceType.None)> _
Public Class Items
    Implements IList
    Private mdict As New ArrayList
    Public Sub CopyTo(ByVal array As System.Array, ByVal index As Integer) Implements System.Collections.ICollection.CopyTo
        mdict.CopyTo(array, index)
    End Sub

    Public ReadOnly Property Count() As Integer Implements System.Collections.ICollection.Count
        Get
            Return mdict.Count
        End Get
    End Property

    Public ReadOnly Property IsSynchronized() As Boolean Implements System.Collections.ICollection.IsSynchronized
        Get
            Return mdict.IsSynchronized
        End Get
    End Property

    Public ReadOnly Property SyncRoot() As Object Implements System.Collections.ICollection.SyncRoot
        Get
            Return mdict.SyncRoot
        End Get
    End Property

    Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Return mdict.GetEnumerator
    End Function

    Public Function Add(ByVal value As Object) As Integer Implements System.Collections.IList.Add
        Return mdict.Add(value)
    End Function

    Public Sub Clear() Implements System.Collections.IList.Clear
        mdict.Clear()
    End Sub

    Public Function Contains(ByVal value As Object) As Boolean Implements System.Collections.IList.Contains
        Return mdict.Contains(value)
    End Function

    Public Function IndexOf(ByVal value As Object) As Integer Implements System.Collections.IList.IndexOf
        Return mdict.IndexOf(value)
    End Function

    Public Sub Insert(ByVal index As Integer, ByVal value As Object) Implements System.Collections.IList.Insert
        mdict.Insert(index, value)
    End Sub

    Public ReadOnly Property IsFixedSize() As Boolean Implements System.Collections.IList.IsFixedSize
        Get
            Return mdict.IsFixedSize
        End Get
    End Property

    Public ReadOnly Property IsReadOnly() As Boolean Implements System.Collections.IList.IsReadOnly
        Get
            Return mdict.IsReadOnly
        End Get
    End Property

    Default Public Property Item(ByVal index As Integer) As Object Implements System.Collections.IList.Item
        Get
            Return mdict.Item(index)
        End Get
        Set(ByVal Value As Object)
            mdict.Item(index) = Value
        End Set
    End Property

    Public Sub Remove(ByVal value As Object) Implements System.Collections.IList.Remove
        mdict.Remove(value)
    End Sub

    Public Sub RemoveAt(ByVal index As Integer) Implements System.Collections.IList.RemoveAt
        mdict.RemoveAt(index)
    End Sub
End Class
 
Old February 7th, 2005, 02:30 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

When I have to do something like this, I often write the data into a file, and give the name of the file to the called process as an argument.

Then you would have the .NET assembly take the filename argument, and go read the file.

Jaucourt’s method is good in that it does not rely on the file system, nor the access permissions associated with all that.
Additionally it has the advantage of being random-access.





Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA, VB, VB.NET,...??? jumpjack Visual Basic 2005 Basics 2 September 24th, 2007 02:52 PM
what I am passing to PROC - VB.net lisabb ASP.NET 2.0 Basics 9 June 8th, 2007 11:41 AM
Passing data to Msword from Vb. kmsantosh Word VBA 1 December 29th, 2006 02:54 AM
VBA Word is very slow with vb.net preeti01 VB How-To 4 May 5th, 2005 05:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.