100% found this document useful (1 vote)
75 views

VBSyntax UserInputFromSetOptions

This document provides guidance on accepting user input in VB.NET through various controls like text boxes, list boxes, check boxes, combo boxes, and option buttons. It explains how to add these controls to a form, populate them with options, and write code to process the user's selection. For example, it demonstrates using an IF statement to check the text in a text box and set a response, or using a ListBox's ListIndex property and IF/Select Case statements to show different images based on the user's selection from a list.

Uploaded by

sedmondsbrown
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
75 views

VBSyntax UserInputFromSetOptions

This document provides guidance on accepting user input in VB.NET through various controls like text boxes, list boxes, check boxes, combo boxes, and option buttons. It explains how to add these controls to a form, populate them with options, and write code to process the user's selection. For example, it demonstrates using an IF statement to check the text in a text box and set a response, or using a ListBox's ListIndex property and IF/Select Case statements to show different images based on the user's selection from a list.

Uploaded by

sedmondsbrown
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

SEB’s VB.

NET Guide

Accepting User Input


Basic Text
1. Add a text box
2. Delete the text in the text property
3. Write the code to process the user input:
 What do you want to activate the code? Use a form_load to automatically run the
code or a command#_click to run it when the user clicks the command button.
(The sub will be created for you if you double-click on the command button or the
form)
 Example:

Private Sub Command1_Click


If Text1.Text = “Hello!” Then
Text1.Text = “Welcome”
ElseIf Text1.Text = “Good-bye” Then
Text1.Text = “See ya!”
Else
Text1.Text = “Sorry. I don’t understand.”
End If
End Sub

List Boxes, Check Boxes, Combos & Option


Buttons
List Boxes:
List boxes allow the user to select from several options in a box.
The user can only choose one from the selected list.

Check Boxes
Check boxes allow the user to tick the options they want to choose. They can
select more than one box.

Page 1 of 3
SEB’s VB.NET Guide

Combos
Combos allow the user to select from a dropdown box

Option Buttons
Option buttons allow the user to choose between the options available.

Using Combos & Lists


1. Build the list of options in your combo or list by adding them in a form_load or
command#_click:

List#.AddItem “Option”

or

Combo#.AddItem “Option” (where # is the number of the option and


option is the name of the choice)

2. Use an IF statement or a case statement to set to code the effect of the user’s choice.

If List#.ListIndex = 0 Then
Image1.Visible = True
ElseIf List#.ListIndex = 1 Then
Image2.Visible = True
Else
Image3.Visible = True
End If

This code assumes all images have previously been set to visible = false. The
ListIndex numbers the options in the list, starting with 0. The case statement is
similar to IF: it is designed for use with a large number of options. The following
case statement would work in the same way.

Page 2 of 3
SEB’s VB.NET Guide

Select Case List#.ListIndex


Case 0
Image1.Visible = True
Case 1
Image2.Visible = True
Case 2
Image3.Visible = True
End Select

Using Check Boxes & Option Buttons


Each check box or option button is added individually. The value of the check box or
option button is tested to check the user’s response.

If Option#.Checked = True Then


Text#.Text = “You have selected option #”
End If

If Check1.checked = True Then


Text#.Text = "You've selected this checkbox"
ElseIf Check1.checked = False Then
Text#.Text = "You've deselected this checkbox"
End If

Page 3 of 3

You might also like