Build a small application that fills a collection (list) with 10 sequential numbers, and then prints the collection(list) in reverse order, skipping every other member, until the entire collection has been displayed. For example, if the collection contained the numbers 1 through 10, they would print as:
10, 8, 6, 4, 2, 9, 7, 5, 3, 1 The print out should be in that order no matter what sequential numbers are in the collection (list). If it were 21 through 30, output would be 30,28,26,24,22,29,27,25,23,21 and so forth.
Note: you must use a collection - do not write down the numbers directly to produce the output. Loops should be employed but the loop control variable should be used as an index or subscript number. Your code should work even if I change the list of sequential numbers to something else. Remember that indexes count from 0 first -- the first item in a collection has index 0, the second item in a collection has index 1, and so forth.
I've got the first part of the problem, getting the numbers in the list box, done with no problem. It's the second part I am struggling with. I cannot get the numbers (I am using 1-10) from the list box to display in reverse order in an adjacent text box. Here's my code so far:
Option Explicit On Option Strict On Option Infer Off Public Class Form1 Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click 'closes the program without error Me.Close() End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'this will put numbers in the list box For lblOrgList As Double = 1 To 10 lstOrgValues.Items.Add(lblOrgList.ToString) Next lblOrgList End Sub End Class
I've tried everything I can think of for the 2nd part, but I can't figure it out at all! Any help, will be greatly appreciated. Thank you!