Getting data from a field in another form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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 said:
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
 
Cor Ligthert said:
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'.
 

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

Back
Top