VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Passing Values between two forms Posted by Grinja on 16 Sept 2005 at 4:41 AM
Hey,
I have to forms A and B.

I Need to pass a value from B to A .
i.e Form A calls form B , I need to get a Value from B back to Form A.

Any help would be appreciated.

Report
Re: Passing Values between two forms Posted by IDK on 16 Sept 2005 at 6:13 AM
: Hey,
: I have to forms A and B.
:
: I Need to pass a value from B to A .
: i.e Form A calls form B , I need to get a Value from B back to Form A.
:
: Any help would be appreciated.
:
:
The func A calls in B could return what you want

Niklas Ulvinge aka IDK

Report
Re: Passing Values between two forms Posted by rlc on 16 Sept 2005 at 7:30 AM
something like thisin form 1?

Dim l_form2 as form2
dim l_SomeValue as string

l_Form2.SomeValue = "if you want to pass something in"
l_form2.showdialog()
l_SomeValue = l_form2.SomeValue
l_form2.dispose

'form 2
Public Class Form2

Dim m_SomeValue as String

   public property someValue
        'what you get return
        Get
            Return m_someValue
        End Get
        'if you want to set before form2
        Set(ByVal Value)
            m_someValue = Value
        End set
    End Property
'''

~rlc
Report
Re: Passing Values between two forms Posted by Grinja on 18 Sept 2005 at 11:50 AM
: something like thisin form 1?
:
: 
: Dim l_form2 as form2
: dim l_SomeValue as string
: 
: l_Form2.SomeValue = "if you want to pass something in"
: l_form2.showdialog()
: l_SomeValue = l_form2.SomeValue
: l_form2.dispose
: 
: 'form 2
: Public Class Form2
: 
: Dim m_SomeValue as String
: 
:    public property someValue
:         'what you get return
:         Get
:             Return m_someValue
:         End Get
:         'if you want to set before form2
:         Set(ByVal Value)
:             m_someValue = Value
:         End set
:     End Property
: '''

: ~rlc
:

Thanks for your response but Im not too sure that this will work for me.

Basically, in Form A I want the user to specify a Supplier.
Form B holds a datagrid with all the suppliers.

The User Clicks on the "Specify" Button which will open form B displaying the "Supplier" datagrid.
The user selects a Supplier from the datagrid and clicks OK.

I can get the relevant info out of the grid using the following code :
"Dim supplierIDcol As Integer = 0
Dim val As Object = Me.DataGrid1(Me.DataGrid1.CurrentRowIndex, supplierIDcol)"

I Need to pass Val back to form A.

Thanks for your help so far!

Report
Re: Passing Values between two forms Posted by rlc on 18 Sept 2005 at 3:35 PM
That should work fine for you. Change the type for the somevalue varibles to object instead of string. So basically put a 'Public Property' of the type you want returned on form B. before you call '.Dispose' on the form B the value will still be accessible through the property even though your user has closed the form. So set the value to a member in form A, then dispose of the other form and continue your processing.

Also it is better to use the actual object's type instead of the 'Object' type. Using 'object' requires the code to dynamically type the objects at runtime (late-binding), which can reduce performance and open your code to errors since the type is not known by the compiler when compiled.


: : something like thisin form 1?
: :
: : 
: : Dim l_form2 as form2
: : dim l_SomeValue as string
: : 
: : l_Form2.SomeValue = "if you want to pass something in"
: : l_form2.showdialog()
: : l_SomeValue = l_form2.SomeValue
: : l_form2.dispose
: : 
: : 'form 2
: : Public Class Form2
: : 
: : Dim m_SomeValue as String
: : 
: :    public property someValue
: :         'what you get return
: :         Get
: :             Return m_someValue
: :         End Get
: :         'if you want to set before form2
: :         Set(ByVal Value)
: :             m_someValue = Value
: :         End set
: :     End Property
: : '''

: : ~rlc
: :
:
: Thanks for your response but Im not too sure that this will work for me.
:
: Basically, in Form A I want the user to specify a Supplier.
: Form B holds a datagrid with all the suppliers.
:
: The User Clicks on the "Specify" Button which will open form B displaying the "Supplier" datagrid.
: The user selects a Supplier from the datagrid and clicks OK.
:
: I can get the relevant info out of the grid using the following code :
: "Dim supplierIDcol As Integer = 0
: Dim val As Object = Me.DataGrid1(Me.DataGrid1.CurrentRowIndex, supplierIDcol)"
:
: I Need to pass Val back to form A.
:
: Thanks for your help so far!
:
:



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.