return value

J

John

I had this working and now it's not. I call one form from another then I
return a value to the first. I had a public sub in the parent form that the
child would call and set the variable. The value in the parent form always
ends up 0 now. Even though it appears the value the child is sending is
correct. As soon as the child form closes the value resets to zero. I'm
not sure why it was working before and now is not. Can anyone explain my
error?
 
H

Herfried K. Wagner [MVP]

John said:
I had this working and now it's not. I call one form from another then I
return a value to the first. I had a public sub in the parent form that
the child would call and set the variable. The value in the parent form
always ends up 0 now. Even though it appears the value the child is
sending is correct. As soon as the child form closes the value resets to
zero. I'm not sure why it was working before and now is not.

See:

<URL:http://groups.google.de/group/microsoft.public.de.german.entwickler.dotnet.vb/msg/255fcb93ea3510e5>
 
L

Linda Liu [MSFT]

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.
 
L

Linda Liu [MSFT]

Hi John,

How about your problem now? Have you checked out what's wrong with your
program?

I think the reason why it wasn't working before may be that the
frmSalesQuote instance you refers in the frmSelectPart IS NOT the
frmSaleQuote instance which is opening. You may use the code
frmSalesQuote.Equals(CType(Me.Owner,frmSalesQuote))¡¯ to check if they are
equal.

If you need our further help, please feel free to post here.


Sincerely,
Linda Liu
Microsoft Online Community Support
 

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

Top