How to pass a variable value from one form to other form Using VB.NET windows application

We will declare the variable public and try to access the value of it in some other form.

 

Say my first form name is ‘frmPayment’ and I declare the public variable in this form like this.

 

Public Class frmPayment

   Public Shared strUnitNo As String

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

 

     strUnitNo =”13568”

 

  End Sub

End Class

 

 

Now I want to fetch the strUnitNo value in some other form. Say we will fetch the information in thankyou form.

 

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

 

  Dim strUnitNo As String = ""

  strUnitNo = frmPayment.strUnitNo

 

 

End Sub

 

We have assgned the strUnitNo value in frmPayment form and use it in Thankyou page.