07 May 2009

VB.Net code: How to pass a public variable intIndex between windows forms

This is an example of passing a public variable intIndex from from1 to form2.

Step 1: Delclare the variable intIndex in Form1 as follows.

 

Public Class Form1

 Inherits System.Windows.Forms.Form

 Public Shared intIndex As Integer

 

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

       intIndex = TextBox1.Text

 Dim myForm As New Form2

       myForm.Show()

 End Sub

 

Step 2: How the form2 access the intIndex variable.

 

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As

 System.EventArgs) Handles MyBase.Load

 TextBox1.Text = Form1.intIndex

End Sub

 

Other note:

Me.close() - to close the form.

No comments: