We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,220 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Passing Variables Between Forms HELP!!

Hi there.
I'm having trouble passing variables between Forms. Let me explian my self by an example.
I have a Form1, the user types a "Client ID" in a textbox if it's not a valid one, it opens a Form2 in which the user selects the correct "Client ID", once selected he presses an OK button.
And there comes the porblem.. it opens a new Form1 with the Client ID that he selected from Form2, but I still have the first Form1 opened.
I have two Form1 opened...

I which to keep the original Form1, but with the value sent from Form2..

I'm using this code:

Code in Form1

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim obj As New Form2
        obj.passedtext = TextBox1.Text
        obj.Show()

    End Sub

Code in Form2

Public Class Form2

    Private _passedtext As String
    Public Property [PassedText]() As String
        Get
            Return _passedText
        End Get
        Set(ByVal Value As String)
            _passedText = Value
        End Set
    End Property

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = _passedtext
    End Sub
2
Contributors
2
Replies
3 Days
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
zeqe
Newbie Poster
2 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

U can directly use the text boxes instead of using property

just giving an example

If I want a value from form1 to form2 then I use following way

code in form1

Textbox1.Text=Form2.Label1.Text

In this way it wont open a new form....In your code u have used

Dim obj As New Form2

so u are getting a new form...just pass variables with form instead of creating property and also u can call the hide() and show() methods of the form

poojavb
Posting Pro
524 posts since Nov 2011
Reputation Points: 39
Solved Threads: 77
Skill Endorsements: 5

It works perfectly... thanks a lot

zeqe
Newbie Poster
2 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by poojavb

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0605 seconds using 2.66MB