More on lists, exceptions, loops and validation
You can use the exception to indicate the error that occurred Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click Dim value As Integer Try value = Integer.Parse(txtinput.Text) Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub
Form expects integer input
Messagebox text comes from the exception.message
Listbox multicolumn property
Setting multicolumn to true
Suppose many values are added to the listbox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Integer For i = 1 To 1000 ListBox1.Items.Add(i) Next End Sub
Note horizontal scrollbar
Checked listbox: checkonclick property defaults to false
A form allowing city selection
Code to get selected cities note you need to clear listbox each time a city is checked or they’ll all be added again Private Sub clbCities_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clbCities.SelectedIndexChanged Dim i, checkint As Integer checkint = -1 lstcities.Items.Clear() For i = 0 To clbCities.Items.Count - 1 If clbCities.GetItemChecked(i) = True Then lstcities.Items.Add(clbCities.Items(i)) End If Next End Sub
As selections are made…