Share Your Source Code or Article

Do you have source code, articles, tutorials, web links, and books to share? You can write your own content here. You can even have your own blog.

Submit now...

Database Programming Made Easy

This tutorial will teach you step by step on how to connect and manipulate database. If you'd like to suggest a tutorial please write a comment at the bottom of this article.

Read more...

Hire Us to Do Your Work

Do you want a customized system? Do you want to setup your own website to do business? Then we are here to help you in your programming needs.

Read more...

Search

Pass values between Windows Forms
admin's picture


0
Your rating: None
Language: 

In my tutorial “How to Pass Value from One Form to another Form” I discussed how the other form received a value by using a Public Variable.

There are so many discussions on the Internet that argues whether Public Variable is a good programming practice compare to Property. Well, IMHO public variable is an option for simplicity. You do not need to waste line of code just to get the same result.

However, there are some certain areas that we need to consider like OOP and Security. Public Variables as the name implies is subject to vulnerabilities. Arjay_nacion has also commented to my tutorial which breaks the encapsulation principle of OOP.

Without further ado let’s get on the code.

Add two forms in your project called “Form1” and “Form2”. Add the necessary controls as shown in the following screenshot.

Pass values between Windows Forms

In Form1 add the following code:

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim Frm2 As Form2
  3.  
  4. Frm2 = New Form2
  5.  
  6. Frm2.GetFolioNumber = txtFolioNumber.Text
  7.  
  8. Frm2.Show()
  9. End Sub

In Form2 add the following code:

  1. Dim FolioNumber As String
  2.  
  3. Public WriteOnly Property GetFolioNumber()
  4. Set(ByVal value)
  5. FolioNumber = value
  6. End Set
  7. End Property
  8.  
  9. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  10. txtFolioNumber.Text = FolioNumber
  11. End Sub

I hope this helps.


Download Code



DENTAL RECORD

Hello,

good day.. hope you can help me.. i need badly an idea about a dental records a patients record.. in visual basic and it records in Access.. thank i'll appreciate if you could help me.. thank you so much.. my e mail is tanchinno@yahoo.com

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <java>, <java5>, <javascript>, <mysql>, <php>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • You may use [inline:xx] tags to display uploaded files or images inline.
  • Links to specified hosts will have a rel="nofollow" added to them.

  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Step by Step Java Tutorial

In this tutorial you will learn how to program with Java. It has a rich of information to be educated well with Java.

Read more...

Do You Have Question?

Do you have any question related to computer programming? Visit our forum and post new topic on the category you like. Be gentle when asking a question.

Ask now...

Point of Sale

Point of Sale is very useful especially for supermarkets or restaurants. I have included a barcode scanner in this program. Please check it out.

Read more...