Ok, this will work, and before you ask to have it altered for each button on your form, why not give it a go on your own first![]()
VB Code:
Private Sub btnUntil_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUntil.Click Dim sbMessage As New System.Text.StringBuilder Dim Indx As Int32 = 0 If Me.lstParts.SelectedItems.Count > 0 Then sbMessage.Append("This is a Do Until loop and you chose the following items: ") Do Until Indx > Me.lstParts.SelectedIndices.Count - 1 If Indx = 0 Then sbMessage.Append(Me.lstParts.SelectedItems(Indx).Text) ElseIf Indx = Me.lstParts.SelectedIndices.Count - 1 Then sbMessage.Append(" and ").Append(Me.lstParts.SelectedItems(Indx).Text) Else sbMessage.Append(", ").Append(Me.lstParts.SelectedItems(Indx).Text) End If Indx += 1 Loop txtLoop.Text = (sbMessage.ToString) Else MessageBox.Show("You did not select any items", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If End Sub




Reply With Quote