473,326 Members | 2,111 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,326 software developers and data experts.

Pass Data between 2 forms

Yeah, I know this question was asked by someone elselike 2 weeks ago. But I
need some additional help. I have a program I'm developing, and multiple
different forms will be opened. For now though, I just have two forms. One is
the main window, and the other sets some preferences like names, and email
addresses.

When someone opens this window, and enters values on this page, I'd like it
to set the values of public variables on the main page.

I'm assuming this can be done, but how?

On the main page, I set a public form2 as 2ndForm = new secondForm

I can access the 2nd form properties from the main page, but not visa-versa.

?????????

Thanks
Jul 21 '05 #1
12 1762
Are you talking about a Windows or Web application?

With WebForm applications, we now use a 1 page paradigm for submitting and
processing form data. With Windows Forms applications, you just need to
declare the variables to Public scope and they will be accessible from the
other form instance.
Did you catch that, the Public variables should be declared on the *first*
form, then they will be available from the second form.

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
Yeah, I know this question was asked by someone elselike 2 weeks ago. But
I
need some additional help. I have a program I'm developing, and multiple
different forms will be opened. For now though, I just have two forms. One
is
the main window, and the other sets some preferences like names, and email
addresses.

When someone opens this window, and enters values on this page, I'd like
it
to set the values of public variables on the main page.

I'm assuming this can be done, but how?

On the main page, I set a public form2 as 2ndForm = new secondForm

I can access the 2nd form properties from the main page, but not
visa-versa.

?????????

Thanks

Jul 21 '05 #2
Yeah. I'm talking about a windows form.
The web form thing I got down.

I did declare them public on the first form... I thought all I needed to do
was to type something like:

(from form 2)
form1.person1.name = "betty"

however, in Visual Studio whenever I try to put something in like that it
underlines it saying "Reference to a non-shared member requires an object
reference."

so... my assumption was incorrect.

I tried creating a reference to it:

public firstForm as Form1

That makes the underlining go away, but during runtime, it throws an
exception:
"Object reference not set to an instance of an object."

so I don't know.
Maybe I'm just not understanding?
"Scott M." wrote:
Are you talking about a Windows or Web application?

With WebForm applications, we now use a 1 page paradigm for submitting and
processing form data. With Windows Forms applications, you just need to
declare the variables to Public scope and they will be accessible from the
other form instance.
Did you catch that, the Public variables should be declared on the *first*
form, then they will be available from the second form.

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
Yeah, I know this question was asked by someone elselike 2 weeks ago. But
I
need some additional help. I have a program I'm developing, and multiple
different forms will be opened. For now though, I just have two forms. One
is
the main window, and the other sets some preferences like names, and email
addresses.

When someone opens this window, and enters values on this page, I'd like
it
to set the values of public variables on the main page.

I'm assuming this can be done, but how?

On the main page, I set a public form2 as 2ndForm = new secondForm

I can access the 2nd form properties from the main page, but not
visa-versa.

?????????

Thanks


Jul 21 '05 #3
Did you actually assign the form1 variable in the second form to point to
form1? I'm pretty certain that you didn't considering the error you're
getting. Anyway, if the fields are indeed public in form1, then it should
be as simple as doing something like this inside form2.cs

// add a field to hold a reference to the main form
private Form1 _mainFrm;

// adjust the constructor to accept the main form's reference
public Form2(Form1 frm)
{
InitializeComponent();

_mainFrm = frm;
_mainFrm.person1.name = "betty";
}
....

Then inside Form1, create the second form using the constructor we just
made:

Form2 f = new Form2(this);
f.ShowDialog();

As a side note, I highly recommend using delegates/events to notify the main
form when something has changed instead of the above.

ShaneB

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
Yeah. I'm talking about a windows form.
The web form thing I got down.

I did declare them public on the first form... I thought all I needed to
do
was to type something like:

(from form 2)
form1.person1.name = "betty"

however, in Visual Studio whenever I try to put something in like that it
underlines it saying "Reference to a non-shared member requires an object
reference."

so... my assumption was incorrect.

I tried creating a reference to it:

public firstForm as Form1

That makes the underlining go away, but during runtime, it throws an
exception:
"Object reference not set to an instance of an object."

so I don't know.
Maybe I'm just not understanding?

Jul 21 '05 #4
You need to have an instance of Form1 before you can use any of its public
members in Form2.

This (form1.person1.name = "betty") won't work unless you have an instance
of Form1 still in accessible memory. And, this (public firstForm as Form1)
does declare an object variable of the right type (so no underline), but
doesn't give you an instance of the object to work with because you didn't
include the keyword "new" in the statement.

It actually is simple and you are very close. Your problem is that you
don't have an instance of Form1 in memory when you are using Form2. Show us
all of your code.
"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
Yeah. I'm talking about a windows form.
The web form thing I got down.

I did declare them public on the first form... I thought all I needed to
do
was to type something like:

(from form 2)
form1.person1.name = "betty"

however, in Visual Studio whenever I try to put something in like that it
underlines it saying "Reference to a non-shared member requires an object
reference."

so... my assumption was incorrect.

I tried creating a reference to it:

public firstForm as Form1

That makes the underlining go away, but during runtime, it throws an
exception:
"Object reference not set to an instance of an object."

so I don't know.
Maybe I'm just not understanding?
"Scott M." wrote:
Are you talking about a Windows or Web application?

With WebForm applications, we now use a 1 page paradigm for submitting
and
processing form data. With Windows Forms applications, you just need to
declare the variables to Public scope and they will be accessible from
the
other form instance.
Did you catch that, the Public variables should be declared on the
*first*
form, then they will be available from the second form.

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
> Yeah, I know this question was asked by someone elselike 2 weeks ago.
> But
> I
> need some additional help. I have a program I'm developing, and
> multiple
> different forms will be opened. For now though, I just have two forms.
> One
> is
> the main window, and the other sets some preferences like names, and
> email
> addresses.
>
> When someone opens this window, and enters values on this page, I'd
> like
> it
> to set the values of public variables on the main page.
>
> I'm assuming this can be done, but how?
>
> On the main page, I set a public form2 as 2ndForm = new secondForm
>
> I can access the 2nd form properties from the main page, but not
> visa-versa.
>
> ?????????
>
> Thanks


Jul 21 '05 #5
I'm getting close? Score!

Okay. The only thing I have on form2 right now is a button. Right now, all
that button does is set some variables on form1 (until I get things working).
Here is my code on form2:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim mainGame As game.gameMain 'set reference to form 1
mainGame.Owner = Me ' dont know if I need this
mainGame.player1.playerName = "Nive" 'set the player1's name to Nive
mainGame.player1.Department = "Accounting" 'set her department
End Sub

the player1 variable is declared in form1 (from a seperate class):
Public player1 As player = New player 'create player1

Any ideas?
"Scott M." wrote:
You need to have an instance of Form1 before you can use any of its public
members in Form2.

This (form1.person1.name = "betty") won't work unless you have an instance
of Form1 still in accessible memory. And, this (public firstForm as Form1)
does declare an object variable of the right type (so no underline), but
doesn't give you an instance of the object to work with because you didn't
include the keyword "new" in the statement.

It actually is simple and you are very close. Your problem is that you
don't have an instance of Form1 in memory when you are using Form2. Show us
all of your code.
"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
Yeah. I'm talking about a windows form.
The web form thing I got down.

I did declare them public on the first form... I thought all I needed to
do
was to type something like:

(from form 2)
form1.person1.name = "betty"

however, in Visual Studio whenever I try to put something in like that it
underlines it saying "Reference to a non-shared member requires an object
reference."

so... my assumption was incorrect.

I tried creating a reference to it:

public firstForm as Form1

That makes the underlining go away, but during runtime, it throws an
exception:
"Object reference not set to an instance of an object."

so I don't know.
Maybe I'm just not understanding?
"Scott M." wrote:
Are you talking about a Windows or Web application?

With WebForm applications, we now use a 1 page paradigm for submitting
and
processing form data. With Windows Forms applications, you just need to
declare the variables to Public scope and they will be accessible from
the
other form instance.
Did you catch that, the Public variables should be declared on the
*first*
form, then they will be available from the second form.

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
> Yeah, I know this question was asked by someone elselike 2 weeks ago.
> But
> I
> need some additional help. I have a program I'm developing, and
> multiple
> different forms will be opened. For now though, I just have two forms.
> One
> is
> the main window, and the other sets some preferences like names, and
> email
> addresses.
>
> When someone opens this window, and enters values on this page, I'd
> like
> it
> to set the values of public variables on the main page.
>
> I'm assuming this can be done, but how?
>
> On the main page, I set a public form2 as 2ndForm = new secondForm
>
> I can access the 2nd form properties from the main page, but not
> visa-versa.
>
> ?????????
>
> Thanks


Jul 21 '05 #6
Well your problem is just as I said, you aren't making a reference to form1
at all, you are only making an object variable of the form1 type. What you
don't say below is if there is an instance of Form1 already when Form2 is
launched.

If there is, then your code needs to be:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'I am assuming that "mainGame" is the name of the instance of the
Form1 class
mainGame.player1.playerName = "Nive" 'set the player1's name to Nive
mainGame.player1.Department = "Accounting" 'set her department
End Sub

************************************************** ***********************

If there isn't, then the code should be:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'...Notice the keyword "NEW" below.....
Dim mainGame As NEW game.gameMain 'set reference to NEW INSTANCE OF
form 1
mainGame.player1.playerName = "Nive" 'set the player1's name to Nive
mainGame.player1.Department = "Accounting" 'set her department
End Sub

So essentially it boils down to which form is instantiated first (form1 or
form2). If there is already an instance of form1, then you just simply
access its public members. If there is not an instance of form1 when form2
is running, then you need to make an instance of form1 (just setting a
variable to the type of form1 isn't enough).

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
I'm getting close? Score!

Okay. The only thing I have on form2 right now is a button. Right now, all
that button does is set some variables on form1 (until I get things
working).
Here is my code on form2:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim mainGame As game.gameMain 'set reference to form 1
mainGame.Owner = Me ' dont know if I need this
mainGame.player1.playerName = "Nive" 'set the player1's name to
Nive
mainGame.player1.Department = "Accounting" 'set her department
End Sub

the player1 variable is declared in form1 (from a seperate class):
Public player1 As player = New player 'create player1

Any ideas?
"Scott M." wrote:
You need to have an instance of Form1 before you can use any of its
public
members in Form2.

This (form1.person1.name = "betty") won't work unless you have an
instance
of Form1 still in accessible memory. And, this (public firstForm as
Form1)
does declare an object variable of the right type (so no underline), but
doesn't give you an instance of the object to work with because you
didn't
include the keyword "new" in the statement.

It actually is simple and you are very close. Your problem is that you
don't have an instance of Form1 in memory when you are using Form2. Show
us
all of your code.
"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
> Yeah. I'm talking about a windows form.
> The web form thing I got down.
>
> I did declare them public on the first form... I thought all I needed
> to
> do
> was to type something like:
>
> (from form 2)
> form1.person1.name = "betty"
>
> however, in Visual Studio whenever I try to put something in like that
> it
> underlines it saying "Reference to a non-shared member requires an
> object
> reference."
>
> so... my assumption was incorrect.
>
> I tried creating a reference to it:
>
> public firstForm as Form1
>
> That makes the underlining go away, but during runtime, it throws an
> exception:
> "Object reference not set to an instance of an object."
>
> so I don't know.
> Maybe I'm just not understanding?
>
>
> "Scott M." wrote:
>
>> Are you talking about a Windows or Web application?
>>
>> With WebForm applications, we now use a 1 page paradigm for submitting
>> and
>> processing form data. With Windows Forms applications, you just need
>> to
>> declare the variables to Public scope and they will be accessible from
>> the
>> other form instance.
>> Did you catch that, the Public variables should be declared on the
>> *first*
>> form, then they will be available from the second form.
>>
>> "Casey" <Ca***@discussions.microsoft.com> wrote in message
>> news:C4**********************************@microsof t.com...
>> > Yeah, I know this question was asked by someone elselike 2 weeks
>> > ago.
>> > But
>> > I
>> > need some additional help. I have a program I'm developing, and
>> > multiple
>> > different forms will be opened. For now though, I just have two
>> > forms.
>> > One
>> > is
>> > the main window, and the other sets some preferences like names, and
>> > email
>> > addresses.
>> >
>> > When someone opens this window, and enters values on this page, I'd
>> > like
>> > it
>> > to set the values of public variables on the main page.
>> >
>> > I'm assuming this can be done, but how?
>> >
>> > On the main page, I set a public form2 as 2ndForm = new secondForm
>> >
>> > I can access the 2nd form properties from the main page, but not
>> > visa-versa.
>> >
>> > ?????????
>> >
>> > Thanks
>>
>>
>>


Jul 21 '05 #7
Your correct. The first form is already loaded when form 2 is opened.
Here's how I open form2 from form1.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim setupForm As secondForm = New secondForm
setupForm.Show()
End Sub

I guess, the only thing I'm still confused about is how I reference the
first form from form 2?
When I try to access form1's public variables, I get "Object reference not
set to an instance of an object."

So I have to do somehting...

Thanks for the Help Scott M. I'm mostly an asp.net programmer. Windows
programming is somehting I haven't needed to work with until now.

-- Casey

"Scott M." wrote:
Well your problem is just as I said, you aren't making a reference to form1
at all, you are only making an object variable of the form1 type. What you
don't say below is if there is an instance of Form1 already when Form2 is
launched.

If there is, then your code needs to be:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'I am assuming that "mainGame" is the name of the instance of the
Form1 class
mainGame.player1.playerName = "Nive" 'set the player1's name to Nive
mainGame.player1.Department = "Accounting" 'set her department
End Sub

************************************************** ***********************

If there isn't, then the code should be:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'...Notice the keyword "NEW" below.....
Dim mainGame As NEW game.gameMain 'set reference to NEW INSTANCE OF
form 1
mainGame.player1.playerName = "Nive" 'set the player1's name to Nive
mainGame.player1.Department = "Accounting" 'set her department
End Sub

So essentially it boils down to which form is instantiated first (form1 or
form2). If there is already an instance of form1, then you just simply
access its public members. If there is not an instance of form1 when form2
is running, then you need to make an instance of form1 (just setting a
variable to the type of form1 isn't enough).

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
I'm getting close? Score!

Okay. The only thing I have on form2 right now is a button. Right now, all
that button does is set some variables on form1 (until I get things
working).
Here is my code on form2:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim mainGame As game.gameMain 'set reference to form 1
mainGame.Owner = Me ' dont know if I need this
mainGame.player1.playerName = "Nive" 'set the player1's name to
Nive
mainGame.player1.Department = "Accounting" 'set her department
End Sub

the player1 variable is declared in form1 (from a seperate class):
Public player1 As player = New player 'create player1

Any ideas?
"Scott M." wrote:
You need to have an instance of Form1 before you can use any of its
public
members in Form2.

This (form1.person1.name = "betty") won't work unless you have an
instance
of Form1 still in accessible memory. And, this (public firstForm as
Form1)
does declare an object variable of the right type (so no underline), but
doesn't give you an instance of the object to work with because you
didn't
include the keyword "new" in the statement.

It actually is simple and you are very close. Your problem is that you
don't have an instance of Form1 in memory when you are using Form2. Show
us
all of your code.
"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
> Yeah. I'm talking about a windows form.
> The web form thing I got down.
>
> I did declare them public on the first form... I thought all I needed
> to
> do
> was to type something like:
>
> (from form 2)
> form1.person1.name = "betty"
>
> however, in Visual Studio whenever I try to put something in like that
> it
> underlines it saying "Reference to a non-shared member requires an
> object
> reference."
>
> so... my assumption was incorrect.
>
> I tried creating a reference to it:
>
> public firstForm as Form1
>
> That makes the underlining go away, but during runtime, it throws an
> exception:
> "Object reference not set to an instance of an object."
>
> so I don't know.
> Maybe I'm just not understanding?
>
>
> "Scott M." wrote:
>
>> Are you talking about a Windows or Web application?
>>
>> With WebForm applications, we now use a 1 page paradigm for submitting
>> and
>> processing form data. With Windows Forms applications, you just need
>> to
>> declare the variables to Public scope and they will be accessible from
>> the
>> other form instance.
>> Did you catch that, the Public variables should be declared on the
>> *first*
>> form, then they will be available from the second form.
>>
>> "Casey" <Ca***@discussions.microsoft.com> wrote in message
>> news:C4**********************************@microsof t.com...
>> > Yeah, I know this question was asked by someone elselike 2 weeks
>> > ago.
>> > But
>> > I
>> > need some additional help. I have a program I'm developing, and
>> > multiple
>> > different forms will be opened. For now though, I just have two
>> > forms.
>> > One
>> > is
>> > the main window, and the other sets some preferences like names, and
>> > email
>> > addresses.
>> >
>> > When someone opens this window, and enters values on this page, I'd
>> > like
>> > it
>> > to set the values of public variables on the main page.
>> >
>> > I'm assuming this can be done, but how?
>> >
>> > On the main page, I set a public form2 as 2ndForm = new secondForm
>> >
>> > I can access the 2nd form properties from the main page, but not
>> > visa-versa.
>> >
>> > ?????????
>> >
>> > Thanks
>>
>>
>>


Jul 21 '05 #8
oh, oh. I think I got it now.
I have to pass the first form TO the second form when I call it from the
first form.
secondform.firstform = me

right? right?

Score!

"Scott M." wrote:
Well your problem is just as I said, you aren't making a reference to form1
at all, you are only making an object variable of the form1 type. What you
don't say below is if there is an instance of Form1 already when Form2 is
launched.

If there is, then your code needs to be:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'I am assuming that "mainGame" is the name of the instance of the
Form1 class
mainGame.player1.playerName = "Nive" 'set the player1's name to Nive
mainGame.player1.Department = "Accounting" 'set her department
End Sub

************************************************** ***********************

If there isn't, then the code should be:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'...Notice the keyword "NEW" below.....
Dim mainGame As NEW game.gameMain 'set reference to NEW INSTANCE OF
form 1
mainGame.player1.playerName = "Nive" 'set the player1's name to Nive
mainGame.player1.Department = "Accounting" 'set her department
End Sub

So essentially it boils down to which form is instantiated first (form1 or
form2). If there is already an instance of form1, then you just simply
access its public members. If there is not an instance of form1 when form2
is running, then you need to make an instance of form1 (just setting a
variable to the type of form1 isn't enough).

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
I'm getting close? Score!

Okay. The only thing I have on form2 right now is a button. Right now, all
that button does is set some variables on form1 (until I get things
working).
Here is my code on form2:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim mainGame As game.gameMain 'set reference to form 1
mainGame.Owner = Me ' dont know if I need this
mainGame.player1.playerName = "Nive" 'set the player1's name to
Nive
mainGame.player1.Department = "Accounting" 'set her department
End Sub

the player1 variable is declared in form1 (from a seperate class):
Public player1 As player = New player 'create player1

Any ideas?
"Scott M." wrote:
You need to have an instance of Form1 before you can use any of its
public
members in Form2.

This (form1.person1.name = "betty") won't work unless you have an
instance
of Form1 still in accessible memory. And, this (public firstForm as
Form1)
does declare an object variable of the right type (so no underline), but
doesn't give you an instance of the object to work with because you
didn't
include the keyword "new" in the statement.

It actually is simple and you are very close. Your problem is that you
don't have an instance of Form1 in memory when you are using Form2. Show
us
all of your code.
"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
> Yeah. I'm talking about a windows form.
> The web form thing I got down.
>
> I did declare them public on the first form... I thought all I needed
> to
> do
> was to type something like:
>
> (from form 2)
> form1.person1.name = "betty"
>
> however, in Visual Studio whenever I try to put something in like that
> it
> underlines it saying "Reference to a non-shared member requires an
> object
> reference."
>
> so... my assumption was incorrect.
>
> I tried creating a reference to it:
>
> public firstForm as Form1
>
> That makes the underlining go away, but during runtime, it throws an
> exception:
> "Object reference not set to an instance of an object."
>
> so I don't know.
> Maybe I'm just not understanding?
>
>
> "Scott M." wrote:
>
>> Are you talking about a Windows or Web application?
>>
>> With WebForm applications, we now use a 1 page paradigm for submitting
>> and
>> processing form data. With Windows Forms applications, you just need
>> to
>> declare the variables to Public scope and they will be accessible from
>> the
>> other form instance.
>> Did you catch that, the Public variables should be declared on the
>> *first*
>> form, then they will be available from the second form.
>>
>> "Casey" <Ca***@discussions.microsoft.com> wrote in message
>> news:C4**********************************@microsof t.com...
>> > Yeah, I know this question was asked by someone elselike 2 weeks
>> > ago.
>> > But
>> > I
>> > need some additional help. I have a program I'm developing, and
>> > multiple
>> > different forms will be opened. For now though, I just have two
>> > forms.
>> > One
>> > is
>> > the main window, and the other sets some preferences like names, and
>> > email
>> > addresses.
>> >
>> > When someone opens this window, and enters values on this page, I'd
>> > like
>> > it
>> > to set the values of public variables on the main page.
>> >
>> > I'm assuming this can be done, but how?
>> >
>> > On the main page, I set a public form2 as 2ndForm = new secondForm
>> >
>> > I can access the 2nd form properties from the main page, but not
>> > visa-versa.
>> >
>> > ?????????
>> >
>> > Thanks
>>
>>
>>


Jul 21 '05 #9
No.

Here, I've tried this myself and it works:

On the first form (Form1):

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Jul 21 '05 #10
Bingo.
You've explained it perfectly, and I've gotten it to work.

You rock dude.

"Scott M." wrote:
No.

Here, I've tried this myself and it works:

On the first form (Form1):

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
.
.
.
#End Region

Public x As Integer = 5
Public y As String = "Test"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim secondForm As New Form2
secondForm.Show()
secondForm.getForm1(Me) ' <--- This is the sub that will pass the
first form instance to the second form
End Sub
End Class

**************************************

On the second form (Form2):

Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
.
.
.
#End Region

Public Sub getForm1(ByVal theForm As Form1)
theForm.x = 6 '<-- You are now accessing the values from form 1
theForm.y = "Something Else"
End Sub
End Class

Jul 21 '05 #11
Happy to help. Good luck!
"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
Bingo.
You've explained it perfectly, and I've gotten it to work.

You rock dude.

"Scott M." wrote:
No.

Here, I've tried this myself and it works:

On the first form (Form1):

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
.
.
.
#End Region

Public x As Integer = 5
Public y As String = "Test"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim secondForm As New Form2
secondForm.Show()
secondForm.getForm1(Me) ' <--- This is the sub that will pass
the
first form instance to the second form
End Sub
End Class

**************************************

On the second form (Form2):

Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
.
.
.
#End Region

Public Sub getForm1(ByVal theForm As Form1)
theForm.x = 6 '<-- You are now accessing the values from form
1
theForm.y = "Something Else"
End Sub
End Class

Jul 21 '05 #12
try to pass the main form as argument in the constructor of second form and
then set the values of main form from the second form. make sure that the
main form members are accessible to the second form from outside.

"Casey" wrote:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I
need some additional help. I have a program I'm developing, and multiple
different forms will be opened. For now though, I just have two forms. One is
the main window, and the other sets some preferences like names, and email
addresses.

When someone opens this window, and enters values on this page, I'd like it
to set the values of public variables on the main page.

I'm assuming this can be done, but how?

On the main page, I set a public form2 as 2ndForm = new secondForm

I can access the 2nd form properties from the main page, but not visa-versa.

?????????

Thanks

Jul 21 '05 #13

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

Similar topics

7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
3
by: Todd Schinell | last post by:
Back in July, Jeffery Tan posted this: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OWOTdf0VDHA.2296%40cpmsftngxa06.phx.gbl In response as to how to get click events from a...
6
by: juky | last post by:
Hi all, I have 2 applications one in VB.net and the other in VC6. I need to pass data between them. How can I do it? what's the best way to implement such communication ? Any comment will be...
1
by: woody | last post by:
I have a bit of a newbie question (basically stated in the subject of the posting). If need to get some data out of a SQL Server Database. Can I use a control from a form to supply a parameter. ...
19
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
4
by: rlntemp-gng | last post by:
I have one module where I would like to launch 2 different forms (that do exist), based on a form object and string that is passed into it. (prmTable is a string, not a table object simply because...
4
by: Lilith | last post by:
I have a form that invokes two other dialog forms for controlling the configuration of the program. The dialogs are invoked modally. Rather than pile up a large number of variables in the primary...
14
by: =?Utf-8?B?Umljaw==?= | last post by:
I have seen examples of passing data from FormB to FormA (Parent To Child) but I need an example of passind data from FormA to FormB. My main form is FormA; I will enter some data in textboxes and...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.