By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,997 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,997 IT Pros & Developers. It's quick & easy.

Getting data from a field in another form

P: n/a
When i load a form (frmcontract) in the program i write i can load a contract
(cbocontract) as well as many other things, also in this form i can load
another form to deal with expenditure (frmexpenditure) by pressing a button.
Previously in VB6 i could call the data from the cbocontract field in
frmcontract from frmexpenditure by saying:

whatever=frmcontract.cbocontract.text

In VB.NET i can't do this and no matter how hard i try (obviously not hard
enough) i can't find a way of doing it. How is it done?
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
RBirney,

You can do it in VBNet as well, however it is not good OOP programming. You
make your form classes completly dependable from each other.

Better is to share your data in a whatever global class.
Sample
\\\
Public Class MyData
Public Shared myfield as string
End Class
///

Now you can use myfield everywhere in your project as
MyData.myfield

(This is a the most simple approach just to show you how it goes)

I hope this helps?

Cor
"RBirney" <RB*****@discussions.microsoft.com>
When i load a form (frmcontract) in the program i write i can load a
contract
(cbocontract) as well as many other things, also in this form i can load
another form to deal with expenditure (frmexpenditure) by pressing a
button.
Previously in VB6 i could call the data from the cbocontract field in
frmcontract from frmexpenditure by saying:

whatever=frmcontract.cbocontract.text

In VB.NET i can't do this and no matter how hard i try (obviously not hard
enough) i can't find a way of doing it. How is it done?

Nov 21 '05 #2

P: n/a
RBirney wrote:
When i load a form (frmcontract) in the program i write i can load a contract
(cbocontract) as well as many other things, also in this form i can load
another form to deal with expenditure (frmexpenditure) by pressing a button.
Previously in VB6 i could call the data from the cbocontract field in
frmcontract from frmexpenditure by saying:

whatever=frmcontract.cbocontract.text

In VB.NET i can't do this and no matter how hard i try (obviously not hard
enough) i can't find a way of doing it. How is it done?


Is frmcontract visible to your frmexpenditure? IOW, is that a global
variable? If not, then frmexpenditure doesn't know that variable and the
code doesn't work. Now if you always call frmexpenditure only from
frmcontract, you could try me.parent.cbocontract.text, presuming you
called the form as follows from frmcontract:

dim frmExpenditure as new clsExpenditure() 'I always call my form
clsSomething so I can call the referring vars frmSomething
frmExpenditure.showdialog(me)

or something similar.

Another way could be to define a public var in your frmexpenditure like
Dim cContract as String()

Then in frmContract do something like:
dim frmExpenditure as new clsExpenditure()
frmExpenditure.cContract="whatever"
frmExpenditure.showdialog(me)

Then you'd have a var cContract available in your Expenditure form.

Rinze van Huizen
Nov 21 '05 #3

P: n/a
"Cor Ligthert" <no************@planet.nl> schrieb:
Better is to share your data in a whatever global class.
Sample
\\\
Public Class MyData
Public Shared myfield as string
End Class
///

Now you can use myfield everywhere in your project as
MyData.myfield

(This is a the most simple approach just to show you how it goes)


Yep. Notice that by using this approach the same field will be shared
between all instances of 'MyData'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.