By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,499 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Sep 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Rudy" <Ru**@discussions.microsoft.comwrote in message
news:51**********************************@microsof t.com...
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


Sep 17 '06 #2

P: n/a
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

"ChrisRM" wrote:
>
"Rudy" <Ru**@discussions.microsoft.comwrote in message
news:51**********************************@microsof t.com...
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


Sep 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.