Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

How to access Windows Form Variable into Another Form using Visual Basic.Net

Author: DevASP
Download Source Code :

In this simple article you will learn that how to access windows form variable of one form in other form.

Create a VB.Net Application and drag two buttons and a textbox now do these steps


ProjectàAdd Module


Now this is code for the module


Public Module Module1


    Public common As String


End Module

Here common is the variable which is access to every class or form in whole Application. 

Now right code on save button click event

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Module1.common = TextBox1.Text


End Sub

Now write code on form Load button click

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


        Dim frm As New Form2



End Sub

After this all add a new form and drag a label on it and write code on its load event

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


        Label1.Text = Module1.common


End Sub 

Article Comments
thankx for code.
as i was trying to access formobject.variablename but i was unable to acess it.

Posted on 3/7/2007 6:27:44 AM by bharati

it is really fantastic. it works and help me alot.
Thanx for this coding.
Naresh Rajput Kashyap

Posted on 8/31/2007 6:37:11 AM by Naresh Rajput

i am a beginner programer. i want Visual code .When textbox input 10 then label .text is ten

Posted on 2/2/2010 12:22:37 AM by nurunnabi

Thanks.It was very helpful to me.

Posted on 3/29/2010 1:50:40 AM by nayomi


Posted on 4/17/2010 5:14:32 PM by mixail

OK. I want to access the textbox value from the module. Dont tell me I have to declare a variable for every control and every control's properties. Or could modules be a nasty no no in DotNET? I have google and yahooed and I cant find ANY example anywhere of how to access properties of form controls from a module. My six year old could do it in VB6. How???

Posted on 7/23/2010 12:12:48 PM by darveson

Add Article Comment:
Name :
Email Address :
Comments :
<< How to Attach Context Menu with System Tray Icon in Your VB.Net Application

Disclaimer - Privacy
© 2002-2017