Hi John,
Is the variable defined in the parent form? How do you pass the value from
the second form to the first form?
I performed a test as follows. I set up a Windows application project and
add two forms named Form1 and Form2. I add two buttons in Form1, let's call
them button1 and button2. I also add a public method and a private variable
in Form1. The code in Form1 is like below.
Public Class Form1
Private val As Integer
Public Sub method(ByVal i As Integer)
val = i
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim frm As New Form2
frm.Owner = Me
frm.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox(val.ToString())
End Sub
End Class
I add a button called button1 in Form2 too. When this button is clicked,
form2 will call the public method in form1. The following is the code in
Form2.
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CType(Me.Owner, Form1).method(34)
End Sub
End Class
Build the project and run it. When I click the button1 in form1, form2
appears. Then I click the button1 in form2 and close it. I click the
button2 in form1, a message box shows out saying '34'. All is ok.
Is there any difference between your program and mine? If yes, could you
send me a sample project that could just reproduce the problem? To get my
actual email address, remove the 'online' from my displayed email address.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.