Ok, this is probably a no-brainer for most of you but its escaping me and I
can't even seem to find the answer in any documentation. How do you access a
friend variable of one class, from another class in the same project?
Thanks
Blake 9 4789
* "Blake Weaver" <rb******@bellsouth.net> scripsit: Ok, this is probably a no-brainer for most of you but its escaping me and I can't even seem to find the answer in any documentation. How do you access a friend variable of one class, from another class in the same project?
The same way as you do that with a public variable.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
"Blake Weaver" <rb******@bellsouth.net> schrieb Ok, this is probably a no-brainer for most of you but its escaping me and I can't even seem to find the answer in any documentation. How do you access a friend variable of one class, from another class in the same project?
There's no difference to Public variables in the same project.
class C1
friend i as integer
end class
'...
dim o as new c1
o.i = 17 'Access Friend field
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
The same way you access any variable, by its name. But remember, that
Friend scope is namespace scope, so if the 2 classes are not in the same
namespace, Friend won't cut it for you.
"Blake Weaver" <rb******@bellsouth.net> wrote in message
news:zE*****************@bignews3.bellsouth.net... Ok, this is probably a no-brainer for most of you but its escaping me and
I can't even seem to find the answer in any documentation. How do you access
a friend variable of one class, from another class in the same project?
Thanks Blake
Ok, perhaps I've got the wrong idea in my head or perhaps I didn't explain
myself right. I've got a class with a variable in, a control on the form
actually. I've got another class (another form) that I call from the main
form/class. Now, once I display the new form I want to be able to get at
that particular control on the main form. So:
' In Main Form
Private Sub Button1_Click(ByVal sender As system.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim NewForm As New frmChildForm()
NewForm.Show()
End Sub
' In Child Form
....
' I want to access a control (just say a textbox) on the Main Form
' In VB6 you could do something like:
MsgBox frmMainForm.txtTextBox.Text
....
How do I do this in .NET? Or do I need to just change the entrie way I'm
looking at this?
Thanks again,
Blake
"Armin Zingler" <az*******@freenet.de> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl... "Blake Weaver" <rb******@bellsouth.net> schrieb Ok, this is probably a no-brainer for most of you but its escaping me and I can't even seem to find the answer in any documentation. How do you access a friend variable of one class, from another class in the same project?
There's no difference to Public variables in the same project.
class C1 friend i as integer end class
'...
dim o as new c1 o.i = 17 'Access Friend field
-- Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
You can just pass a reference to the main form in the
constructor of your second form:
Public Class Form2
Inherits System.Windows.Forms.Form
Private m_Form1 as Form1
Public Sub New(ByVal FirstForm as Form1)
m_Form1 = FirstForm
m_Form1.txtSomeTextBox.Text = "Some data"
End Sub
End Class
.....in Form1
Dim Form as Form2
Form = New Form2(Me) -----Original Message----- Ok, perhaps I've got the wrong idea in my head or perhaps
I didn't explainmyself right. I've got a class with a variable in, a
control on the formactually. I've got another class (another form) that I
call from the mainform/class. Now, once I display the new form I want to be
able to get atthat particular control on the main form. So:
' In Main Form Private Sub Button1_Click(ByVal sender As system.Object,
ByVal e AsSystem.EventArgs) Handles Button1.Click Dim NewForm As New frmChildForm() NewForm.Show() End Sub
' In Child Form .... ' I want to access a control (just say a textbox) on
the Main Form ' In VB6 you could do something like: MsgBox frmMainForm.txtTextBox.Text ....
How do I do this in .NET? Or do I need to just change the
entrie way I'mlooking at this?
Thanks again, Blake
"Armin Zingler" <az*******@freenet.de> wrote in message news:u8**************@TK2MSFTNGP11.phx.gbl... "Blake Weaver" <rb******@bellsouth.net> schrieb > Ok, this is probably a no-brainer for most of you but
its escaping me > and I can't even seem to find the answer in any
documentation. How do > you access a friend variable of one class, from
another class in the > same project?
There's no difference to Public variables in the same
project. class C1 friend i as integer end class
'...
dim o as new c1 o.i = 17 'Access Friend field
-- Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
.
Thanks Sean, thats exactly what I was trying to do. It was just escaping me,
like I said.
You more question though, would it be better to pass the Form ByVal or
ByRef. As I understand it, ByVal is sending a copy of the form and ByRef is
point me back to the form itself. Seems to me, ByVal would eat up quite a
bit of memory that isn't necessary. But there may be pros to it as well...
or other cons for that matter. Whats your opinion? Others are more than
welcome to respond of course.
Thanks again,
Blake
"Sean" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl... You can just pass a reference to the main form in the constructor of your second form:
Public Class Form2 Inherits System.Windows.Forms.Form Private m_Form1 as Form1
Public Sub New(ByVal FirstForm as Form1)
m_Form1 = FirstForm
m_Form1.txtSomeTextBox.Text = "Some data" End Sub End Class
....in Form1
Dim Form as Form2
Form = New Form2(Me)
-----Original Message----- Ok, perhaps I've got the wrong idea in my head or perhaps I didn't explainmyself right. I've got a class with a variable in, a control on the formactually. I've got another class (another form) that I call from the mainform/class. Now, once I display the new form I want to be able to get atthat particular control on the main form. So:
' In Main Form Private Sub Button1_Click(ByVal sender As system.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click Dim NewForm As New frmChildForm() NewForm.Show() End Sub
' In Child Form .... ' I want to access a control (just say a textbox) on the Main Form ' In VB6 you could do something like: MsgBox frmMainForm.txtTextBox.Text ....
How do I do this in .NET? Or do I need to just change the entrie way I'mlooking at this?
Thanks again, Blake
"Armin Zingler" <az*******@freenet.de> wrote in message news:u8**************@TK2MSFTNGP11.phx.gbl... "Blake Weaver" <rb******@bellsouth.net> schrieb > Ok, this is probably a no-brainer for most of you but its escaping me > and I can't even seem to find the answer in any documentation. How do > you access a friend variable of one class, from another class in the > same project?
There's no difference to Public variables in the same project. class C1 friend i as integer end class
'...
dim o as new c1 o.i = 17 'Access Friend field
-- Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
.
"Blake Weaver" <rb******@bellsouth.net> schrieb Thanks Sean, thats exactly what I was trying to do. It was just escaping me, like I said. You more question though, would it be better to pass the Form ByVal or ByRef. As I understand it, ByVal is sending a copy of the form and ByRef is point me back to the form itself. Seems to me, ByVal would eat up quite a bit of memory that isn't necessary. But there may be pros to it as well... or other cons for that matter. Whats your opinion? Others are more than welcome to respond of course.
Passing the variable ByVal passes a copy of the content of the variable. As
a Form is a reference type, the variable only contains the reference (=4
Bytes) to the Form. Consequently a copy of the reference is passed, not a
copy of the Form.
Passing the variable ByRef passes a reference to the variable. Replace
"variable" by "reference to the Form" (that's what the variable contains),
and you get: Passing the variable ByRef passes a reference to the reference
to the Form.
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Actually, passing the form (which is a Reference-Type) ByVal results in the
passing of a copy of the pointer. Yes, that's right, a copy of the pointer,
not a copy of the form itself. Passing Reference-Types ByVal is a bit
confusing, but that's what you wind up with. You only get a copy when you
pass a Value-Type ByVal.
"Blake Weaver" <rb******@bellsouth.net> wrote in message
news:Sf*******************@bignews5.bellsouth.net. .. Thanks Sean, thats exactly what I was trying to do. It was just escaping
me, like I said. You more question though, would it be better to pass the Form ByVal or ByRef. As I understand it, ByVal is sending a copy of the form and ByRef
is point me back to the form itself. Seems to me, ByVal would eat up quite a bit of memory that isn't necessary. But there may be pros to it as well... or other cons for that matter. Whats your opinion? Others are more than welcome to respond of course.
Thanks again, Blake
"Sean" <an*******@discussions.microsoft.com> wrote in message news:05****************************@phx.gbl... You can just pass a reference to the main form in the constructor of your second form:
Public Class Form2 Inherits System.Windows.Forms.Form Private m_Form1 as Form1
Public Sub New(ByVal FirstForm as Form1)
m_Form1 = FirstForm
m_Form1.txtSomeTextBox.Text = "Some data" End Sub End Class
....in Form1
Dim Form as Form2
Form = New Form2(Me)
-----Original Message----- Ok, perhaps I've got the wrong idea in my head or perhaps I didn't explainmyself right. I've got a class with a variable in, a control on the formactually. I've got another class (another form) that I call from the mainform/class. Now, once I display the new form I want to be able to get atthat particular control on the main form. So:
' In Main Form Private Sub Button1_Click(ByVal sender As system.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click Dim NewForm As New frmChildForm() NewForm.Show() End Sub
' In Child Form .... ' I want to access a control (just say a textbox) on the Main Form ' In VB6 you could do something like: MsgBox frmMainForm.txtTextBox.Text ....
How do I do this in .NET? Or do I need to just change the entrie way I'mlooking at this?
Thanks again, Blake
"Armin Zingler" <az*******@freenet.de> wrote in message news:u8**************@TK2MSFTNGP11.phx.gbl... > "Blake Weaver" <rb******@bellsouth.net> schrieb > > Ok, this is probably a no-brainer for most of you but its escaping me> > and I can't even seem to find the answer in any documentation. How do> > you access a friend variable of one class, from another class in the> > same project? > > There's no difference to Public variables in the same project.> > class C1 > friend i as integer > end class > > '... > > dim o as new c1 > o.i = 17 'Access Friend field > > > -- > Armin > > http://www.plig.net/nnq/nquote.html > http://www.netmeister.org/news/learn2quote.html >
.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steven T. Hatton |
last post by:
I find the surprising. If I derive Rectangle from Point, I can access the
members of Point inherited by Rectangle _IF_ they are actually members of a
Rectangle. If I have a member of type Point...
|
by: keepyourstupidspam |
last post by:
Hello,
I have a class X with a member function setConfigValues(). I want to
access this member function in another class Y. Y is not inherited from
X. A member function of class X called run()...
|
by: Joel Moore |
last post by:
I'm a little confused here. If I have the following:
Public ClassA
Friend varA As Integer
Private varB As Integer
Private ClassB
Public Sub MethodA()
' How can I access varA and varB here?...
|
by: dwok |
last post by:
I have been wondering this for a while now. Suppose I have a class
that contains some private member variables. How should I access the
variables throughout the class? Should I use properties that...
|
by: MrJim |
last post by:
How should variables be declared and referenced in both the base and
derived form so they can be accessed?
|
by: toton |
last post by:
Hi,
I have a parser interface , which is
class IParser{
public:
void readHeader(Document& doc)= 0;
void readCC(CC& cc) = 0;
};
Now, there are 3 kinds of parser which extends (implements)...
|
by: earthwormgaz |
last post by:
Is the following legal?
class Outer
{
class Inner
{
private:
Inner() { }
};
|
by: jthep |
last post by:
I have been given the class definition below:
class llist
{
private:
record *start;
char filename;
int readfile();
int writefile();
record * reverse(record *);
|
by: Immortal_Nephi |
last post by:
I want to show you an example how two classes can have relationship
instead of an inheritance. The inheritance is not an option if you
want to define two classes.
The relationship between two...
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |