473,382 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

problem passing structure to constructor

Hello,

I created a public Structure in a Standard Module and also
an array of Structures. Then I load data into the array
of structures in a public sub that I call on the Form load
event. Next I have a class, and I want to pass a
structure member from my array of Structures to the class
constructor. In the form I instantiate a class object.

Module1
--------------------------
Public arrStruct() As structOne

Public Structure structOne
....
End Structure

public sub LoadStruct()
....
End Sub
-----------------------------

Form1
form_load event
LoadStruct
....
Dim clsOne(arrStruct(1)) As New Class1

In the class constructor I have this:

Public Class Class1
Public Sub New(ByVal strcOne As structOne)
var1 = strcOne.element1
var2 = strcOne.element2
...
End Sub
....

The compile error I get is

'strcOne' cannot expose a Friend type outside of the
Public class 'Class1'. strcOne is the the argument in the
constructor for Class1. When I instantiate Class1 as
clsOne I pass a member of my array of Structures,
arrStruct(1) where the member is a structure.

Is there anything I can do to get around this error?

Thanks,
Steve
Nov 21 '05 #1
3 1741
OK. One workaround that I just tried which seems to work
is to declare the Class as Friend instead of Public. Any
suggestions appreciated if this is correct or I am just
getting lucky. If it is just luck, I respectfully request
how to do it correctly.

-----Original Message-----
Hello,

I created a public Structure in a Standard Module and alsoan array of Structures. Then I load data into the array
of structures in a public sub that I call on the Form loadevent. Next I have a class, and I want to pass a
structure member from my array of Structures to the class
constructor. In the form I instantiate a class object.

Module1
--------------------------
Public arrStruct() As structOne

Public Structure structOne
....
End Structure

public sub LoadStruct()
....
End Sub
-----------------------------

Form1
form_load event
LoadStruct
....
Dim clsOne(arrStruct(1)) As New Class1

In the class constructor I have this:

Public Class Class1
Public Sub New(ByVal strcOne As structOne)
var1 = strcOne.element1
var2 = strcOne.element2
...
End Sub
....

The compile error I get is

'strcOne' cannot expose a Friend type outside of the
Public class 'Class1'. strcOne is the the argument in theconstructor for Class1. When I instantiate Class1 as
clsOne I pass a member of my array of Structures,
arrStruct(1) where the member is a structure.

Is there anything I can do to get around this error?

Thanks,
Steve
.

Nov 21 '05 #2
I believe you should declare you structures as public in the class module;

Class Module
Public Class MyClass

Public Structure MyStruct
......
End Structure

Public Sub New(ByVal FileName As String)
MyBase.New( data as MyStruct)
sClear()
FileH.Name = FileName
End Sub

End Class
......................................
Module 1
Public Sub Main()
dim aStruct as myClass.MyStruct

' Set aStruct members to your data
dim newobject as myClass = New MyClass(aStruct)

end sub
"Steve" wrote:
OK. One workaround that I just tried which seems to work
is to declare the Class as Friend instead of Public. Any
suggestions appreciated if this is correct or I am just
getting lucky. If it is just luck, I respectfully request
how to do it correctly.

-----Original Message-----
Hello,

I created a public Structure in a Standard Module and

also
an array of Structures. Then I load data into the array
of structures in a public sub that I call on the Form

load
event. Next I have a class, and I want to pass a
structure member from my array of Structures to the class
constructor. In the form I instantiate a class object.

Module1
--------------------------
Public arrStruct() As structOne

Public Structure structOne
....
End Structure

public sub LoadStruct()
....
End Sub
-----------------------------

Form1
form_load event
LoadStruct
....
Dim clsOne(arrStruct(1)) As New Class1

In the class constructor I have this:

Public Class Class1
Public Sub New(ByVal strcOne As structOne)
var1 = strcOne.element1
var2 = strcOne.element2
...
End Sub
....

The compile error I get is

'strcOne' cannot expose a Friend type outside of the
Public class 'Class1'. strcOne is the the argument in

the
constructor for Class1. When I instantiate Class1 as
clsOne I pass a member of my array of Structures,
arrStruct(1) where the member is a structure.

Is there anything I can do to get around this error?

Thanks,
Steve
.

Nov 21 '05 #3
Steve,
Modules by default are Friends, when you define a Structure inside of a
Module it will also be Friend (despite saying Public on the Structure VB.NET
will not promote the visibility higher then the containing type.

I would move the definition of the Structure outside of the Module.

Module Module1
--------------------------
Public arrStruct() As structOne
public sub LoadStruct()
...
End Sub
----------------------------- End Module
Public Structure structOne
...
End Structure
I normally define structures in their own source file, where each Structure
is in its own source file.

Hope this helps
Jay

"Steve" <an*******@discussions.microsoft.com> wrote in message
news:28****************************@phx.gbl... Hello,

I created a public Structure in a Standard Module and also
an array of Structures. Then I load data into the array
of structures in a public sub that I call on the Form load
event. Next I have a class, and I want to pass a
structure member from my array of Structures to the class
constructor. In the form I instantiate a class object.

Module1
--------------------------
Public arrStruct() As structOne

Public Structure structOne
...
End Structure

public sub LoadStruct()
...
End Sub
-----------------------------

Form1
form_load event
LoadStruct
...
Dim clsOne(arrStruct(1)) As New Class1

In the class constructor I have this:

Public Class Class1
Public Sub New(ByVal strcOne As structOne)
var1 = strcOne.element1
var2 = strcOne.element2
...
End Sub
...

The compile error I get is

'strcOne' cannot expose a Friend type outside of the
Public class 'Class1'. strcOne is the the argument in the
constructor for Class1. When I instantiate Class1 as
clsOne I pass a member of my array of Structures,
arrStruct(1) where the member is a structure.

Is there anything I can do to get around this error?

Thanks,
Steve

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: muser | last post by:
The following function gives me the following error: warning C4700: local variable 'Newirrecord' used without having been initialized. Newirrecord is the instance of a structure. I get the same...
1
by: Sandy | last post by:
Hi, I have some data stored in my internal data structure. I am writing this data in an xml file and invoking xalan on this file to perform some transformation. After the transformation I want...
11
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
4
by: Robert W. | last post by:
I have a data model with this structure: Class PropertyA PropertyB Collection Class Property1 Property2 The outermost class has a handler that correctly deals with events fired by
17
by: Ashwin | last post by:
hi guys, i have overloaded the << operator.as shown below. ostream& operator<<(ostream &out, const student &a) { out<<a.idno; out<< " " ; // out<< a.name; out<< " " ; // out<< a.marks...
11
by: aaragon | last post by:
Hi everyone. I'm trying to write a class with policy based design (Alexandrescu's Modern C++ Design). I'm not a programmer but an engineer so this is kind of hard for me. Through the use of...
5
by: nass | last post by:
this is a thought experiment. i do not have the time to implement it and test it to see if it works so i am relying on your good will:) thank you in advance im on a linux machine (slackware...
3
by: ishwarbg | last post by:
Hi Everyone, I have a .Net Application, through which I am invoking a function from a legacy DLL developed in C++. My structure in C# contains some data of type double which I need to pass to to...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.