passing a structure

D

Dave Cullen

I want to call a function using my own data type as an argument. The
declaration for my function looks like this:

Public Function CreateCardInfo(ByVal data As WoData)


VB.NET balks at this, saying:

'data' cannot expose a Friend type outside of the Public class
'frmMain'.


The Structure WoData is defined in a module, with Public access:

Public Structure WoData
Dim CUST_NAME As String
Dim MFG_SITE As String
Dim PO_NO, SO_NO, LINE_NO As String
Dim DUE_DATE As String
Dim WO_NO As String
Dim QTY As Integer
End Structure

What to do, please?

Thanks
 
I

Imran Koradia

Define your Module as Public. Since you are using the structure as an
argument to a public method, the structure should be available publicly as
well. However, since you've defined your module Friend (not specifying an
access modifier defaults it to Friend), the structure also has 'Friend'
visibility which is why you get the error saying the your structure is a
friend type and cannot be exposed outside a public class.

hope that helps..
Imran.
 
M

Mike McIntyre [MVP]

If you used a VB.NET standard module it will have been given Friend scope
implicitly unless you added the keyword Public e.g.

Module X - Friend scope implied.

Public Module X - Public scope explictly declared.


--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
 
J

Jay B. Harlow [MVP - Outlook]

Dave,
In addition to the other comments, move the structure outside of the Module.
In other words define the WoData Structure in a file by itself. What I will
do is add a Class or Module to my project then change the Class or Module
keywords to Structure or Interface.

Something like:

---x--- begin WoData.vb ---x---
Option Strict On
Option Explicit On
Public Structure WoData
Dim CUST_NAME As String
Dim MFG_SITE As String
Dim PO_NO, SO_NO, LINE_NO As String
Dim DUE_DATE As String
Dim WO_NO As String
Dim QTY As Integer
End Structure

---x--- end WoData.vb ---x---

Hope this helps
Jay
 
D

Dave Cullen

That did it, thank you.

drc


Imran said:
Define your Module as Public. Since you are using the structure as an
argument to a public method, the structure should be available publicly as
well. However, since you've defined your module Friend (not specifying an
access modifier defaults it to Friend), the structure also has 'Friend'
visibility which is why you get the error saying the your structure is a
friend type and cannot be exposed outside a public class.

hope that helps..
Imran.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top