pass a value from a text box to another in a diffrent form

G

Guest

Hello All!

I have been trying to figure this out, have recieved alot of help, but it's
just not clicking in the ol' noggin. I basicly have a value in a text box, I
need to keep that value and pass it on to another textbox on another form.
I understand that there is a couple of ways of doing this, one by using a
public class. The other by a public property. Here is my feeble attempt.
Public Class FormA
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public x As Integer
Public y As String = TextBox1.text
Private Sub FormA_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 FormB
secondForm.Show()
secondForm.getForm1(Me)

End Sub
End Class

Public Class FormB
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

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

End Sub
Public Sub getForm1(ByVal theform As FormA)
theform.x = 6
theform.y = TextBoxB.Text

End Sub

End Class

I'm not sure where I'm going wrong on this. I feel I'm pretty close, just
missing something.
TIA!!

Rudy
 
C

ChrisRM

Rudy said:
Hello All!

I have been trying to figure this out, have recieved alot of help, but
it's
just not clicking in the ol' noggin. I basicly have a value in a text
box, I
need to keep that value and pass it on to another textbox on another form.
I understand that there is a couple of ways of doing this, one by using a
public class. The other by a public property. Here is my feeble attempt.
Public Class FormA
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public x As Integer
Public y As String = TextBox1.text
Private Sub FormA_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 FormB
secondForm.Show()
secondForm.getForm1(Me)

End Sub
End Class

Public Class FormB
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

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

End Sub
Public Sub getForm1(ByVal theform As FormA)
theform.x = 6
theform.y = TextBoxB.Text

End Sub

End Class

I'm not sure where I'm going wrong on this. I feel I'm pretty close, just
missing something.
TIA!!

Rudy

Sorry Rudy, Its not clear what you are trying to do from this code.
Could you give a short Spec of the required flow and a description of what
it is not doing.


Currently the code is attempting to place the values from FormB back into
FormA fields as soon as it is instantiated. I would guess at this time it
would be empty as it has only just painted on the screen. I assume this is
not what you want to do.

If this is what you wanted to do then you should probably code it as
theform.y.Text = TextBoxB.Text.


If you are trying to pull a value from FormA into FormB then you need to
code something like this in FormB

Public Sub getForm1(ByVal theform As FormA)

TextBoxB.Text = theform.TextBox1.Text

End Sub
 
G

Guest

Hey Chris!!
That's funny, I'm not sure what I'm trying to do with this code either!. LOL!

Buy I am trying to pull a value from FormA into FormB. Your last suggestion
did the trick, I just had to change that last line you put in.

Thanks alot!

Rudy
 

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