Loading

How to Create a Local Polling System

Submitted by: 
Language: 
Visitors have accessed this post 1750 times.

Introduction:
Welcome to my tutorial on how to create a local polling system in a Visual Basic Application using its Project Settings.

Steps of Creation:
Step 1:

First we need to set our project settings. I have put "str1", "str2" and "str3" to contains the polling string options, "option1", "option2" and "option3" to contain the votes for each option and finally "question" to contain the question.

Step 2:
Now make the appropriate buttons and labels for your form. I have three options so I have put three buttons (one for each option to vote) and three labels (one for each current vote total). Also add a label to contain the question.

Step 3:
Now we are going to make a function to update our labels with the current vote total...

  1. Private Function updateValues()
  2. Label1.Text = My.Settings.str1 & " Votes: " & My.Settings.Option1
  3. Label2.Text = My.Settings.str2 & " Votes: " & My.Settings.Option2
  4. Label3.Text = My.Settings.str3 & " Votes: " & My.Settings.Option3
  5. End Function

Step 4:
Now lets use that new function. On our form load event we want to set the question to the appropriate label and set the labels that contain the total votes for each option...

  1. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  2. updateValues()
  3. Label4.Text = My.Settings.question
  4. End Sub

Step 5:
Finally lets add one to the appropriate option whenever a vote button is clicked and update the total vote counting labels...

  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. My.Settings.Option1 += 1
  3. updateValues()
  4. End Sub
  5.  
  6. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  7. My.Settings.Option2 += 1
  8. updateValues()
  9. End Sub
  10.  
  11. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  12. My.Settings.Option3 += 1
  13. updateValues()
  14. End Sub

Project Complete!
That's it! Below is the full source code and download to the project files.

  1. Public Class Form1
  2. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  3. My.Settings.Option1 += 1
  4. updateValues()
  5. End Sub
  6.  
  7. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  8. My.Settings.Option2 += 1
  9. updateValues()
  10. End Sub
  11.  
  12. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  13. My.Settings.Option3 += 1
  14. updateValues()
  15. End Sub
  16.  
  17. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  18. updateValues()
  19. Label4.Text = My.Settings.question
  20. End Sub
  21.  
  22. Private Function updateValues()
  23. Label1.Text = My.Settings.str1 & " Votes: " & My.Settings.Option1
  24. Label2.Text = My.Settings.str2 & " Votes: " & My.Settings.Option2
  25. Label3.Text = My.Settings.str3 & " Votes: " & My.Settings.Option3
  26. End Function
  27. End Class

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th>
  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.