Further to Multiple Form Query

GornHorse

Well-known member
Joined
May 27, 2003
Messages
105
Location
Australia
Hi,

Is there a special way you need to open Form2 from Form1 so that Form2 can access the variables declared in Form1?

Ie, i open Form2 from Form1 with:
dim frm2 as new Form2()
frm2.Show()

Then, within Form2, i access the public decalred variable (public var as string) with:
tbPassedVal.Text = frm1.var

The frm1 is declared within Form2 as:
dim frm1 as new Form1()



I can see the var from Form2, however, the value is passed as null, when in fact, it should be "BLAH".

Why is this happening? Could somebody please advise a solution that correctly passes the variable to Form2?


Thanks again,
Michelle
:confused:
 
Hi,
My code snippets are as follows...


The two forms are SearchFileRecord and RetrieveFileDetails.


(In SearchFileRecord)
---------------------

Public valSelectedRow As Integer
Public valSelectedFile As String
Public valSelectedPart As String


Private Sub BOTHERSDataGrid_Files_DoubleClick(ByVal sender As System.Object, ByVal ne As System.EventArgs) Handles BOTHERSDataGrid_Files.DoubleClick
valSelectedRow = BOTHERSDataGrid_Files.CurrentCell.RowNumber()
valSelectedFile = BOTHERSDataGrid_Files.Item(valSelectedRow, 0)
valSelectedPart = BOTHERSDataGrid_Files.Item(valSelectedRow, 1)
Dim myfrm As New RetrieveFileDetails()
myfrm.Show()
End Sub



(In RetrieveFileDetails)
------------------------
Dim myformSearchFileRecord As New SearchFileRecord()
Dim valFwdSelectedFile As String
Dim valFwdSelectedPart As String
Dim valFwdSelectedRow As String

Private Sub RetrieveFileDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim blah = myformSearchFileRecord.valSelectedFile
tbCurrentLocation.Text = blah

valFwdSelectedFile = myformSearchFileRecord.valSelectedFile
valFwdSelectedPart = myformSearchFileRecord.valSelectedPart
valFwdSelectedRow = myformSearchFileRecord.valSelectedRow

myformSearchFileRecord.BOTHERS_Connect()
BOTHERS_DataDisplay_Docs()
myformSearchFileRecord.BOTHERS_Close()
BOTHERSDataGrid_Docs.Expand(-1)
End Sub



Unfortunately, all values retrieved from the SearchFileRecord form (valSelectedFile, valSelectedPart and valSelected Row) are returning "null" when retrived from RetrieveFileDetails; however, they have values when accessed by SearchFileRecord.

Your help with this will be much appreciated.

Regards,
Michelle
 
from what i see, the null values are correct.

heres what i think is happening.

1) you created an instance of SearchFileRecord
2) in that, you created an instance of RetrieveFileDetails
3) you created yet another instance of SearchFileRecord and attempted to get values from that, instead of that created in step 1).
 
Ok then, that makes sense. I went through the debug, and it does create 2 instances of the SearchFileRecord.

How can i code it so that it only declares the instance once??
Thanks.
 
how does the logic of your program go?

1) create an instance (frmSearch) of SearchFileRecord.
2) from it, create an instance of RetrieveFileDetails (frmRetrieve)
3) Get the values from frmSearch in frmRetrieve

is that right?
 
I create the instance of RetriveFileDetails -> that goes to RetrieveFileDetails and creates an instance of frmSearch -> when i actually open RetrieveFileDetails, another instance of frmSearch is created.

Therefore:
1. instance of RetriveFileDetails
2. instance of frmSearch
3. instance of frmSearch

Cheers,
and thanks for your help with this.

Regards,
Michelle
 
What happens is the following...

1. When i declare dim myfrm as new RetrieveFileDetails within the SearchFileRecord form, the debug shows the next step as going to the RetrieveFileDetails, passing through the public sub new() and therefore initialising dim myfrmSearchFileRecord as SearchFileRecord.

2. When that is initialised, the debug goes back to the SearchFileRecord form and finishes the sub. Then, when i actually .show the RetrieveFileDetails form, the debug once again shows it pass through public sub new() and therefore once again initialises dim myfrmSearchFileRecord as SearchFileRecord.

Any ideas on where i can put the initialisation of the SearchFileRecord instance so that it is still public to the code within RetrieveFileDetails, yet will only initialise once the form is loaded, and not when the instance of RetrieveFileDetails is created?

Your help with this will be much appreciated.

Regards,
Michelle
 
Back
Top