qwertysaur
12-16-2008, 04:00 PM
Basically, my problem is that I have to code a program where you input up to 15 items into a list and the program sorts the list for you. I got the checking for a good number input already, it's the adding to the list that gives me trouble. I know there is a logic error somewhere, I just can't find it. :( Here is my code.
Private Sub btninput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btninput.Click
'variables
Dim intnumberofentries As Integer = 1
Dim stritemtoenter As String = ""
Dim strinputboxheading As String = "Enter the name of item # "
Dim striteminlist As String = stra
'conversion
intnumberofitems = Convert.ToInt32(Me.txtnumberofentries.Text)
stritemtoenter = InputBox(strinputboxheading & intnumberofentries, _
"Add an item", "")
'loop begins here
Do Until intnumberofentries > intnumberofitems
Me.lstinput.Items.Add(stritemtoenter)
intnumberofentries += 1
Select Case intnumberofentries
Case 1
stritemtoenter = stra
Case 2
stritemtoenter = strb
Case 3
stritemtoenter = strc
Case 4
stritemtoenter = strd
Case 5
stritemtoenter = stre
Case 6
stritemtoenter = strf
Case 7
stritemtoenter = strg
Case 8
stritemtoenter = strh
Case 9
stritemtoenter = stri
Case 10
stritemtoenter = strj
Case 11
stritemtoenter = strk
Case 12
stritemtoenter = strl
Case 13
stritemtoenter = strm
Case 14
stritemtoenter = strn
Case 15
stritemtoenter = stro
End Select
Loop
Select Case intnumberofitems
Case 1
ReDim Preserve strlistofitems(0)
Case 2
ReDim Preserve strlistofitems(1)
Case 3
ReDim Preserve strlistofitems(2)
Case 4
ReDim Preserve strlistofitems(3)
Case 5
ReDim Preserve strlistofitems(4)
Case 6
ReDim Preserve strlistofitems(5)
Case 7
ReDim Preserve strlistofitems(6)
Case 8
ReDim Preserve strlistofitems(7)
Case 9
ReDim Preserve strlistofitems(8)
Case 10
ReDim Preserve strlistofitems(9)
Case 11
ReDim Preserve strlistofitems(10)
Case 12
ReDim Preserve strlistofitems(11)
Case 13
ReDim Preserve strlistofitems(12)
Case 14
ReDim Preserve strlistofitems(13)
Case 15
ReDim Preserve strlistofitems(14)
End Select
Array.Sort(strlistofitems)
For Each srtiteminlist In strlistofitems
Me.lstoutput.Items.Add(striteminlist)
Next
End Sub
Private Sub btninput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btninput.Click
'variables
Dim intnumberofentries As Integer = 1
Dim stritemtoenter As String = ""
Dim strinputboxheading As String = "Enter the name of item # "
Dim striteminlist As String = stra
'conversion
intnumberofitems = Convert.ToInt32(Me.txtnumberofentries.Text)
stritemtoenter = InputBox(strinputboxheading & intnumberofentries, _
"Add an item", "")
'loop begins here
Do Until intnumberofentries > intnumberofitems
Me.lstinput.Items.Add(stritemtoenter)
intnumberofentries += 1
Select Case intnumberofentries
Case 1
stritemtoenter = stra
Case 2
stritemtoenter = strb
Case 3
stritemtoenter = strc
Case 4
stritemtoenter = strd
Case 5
stritemtoenter = stre
Case 6
stritemtoenter = strf
Case 7
stritemtoenter = strg
Case 8
stritemtoenter = strh
Case 9
stritemtoenter = stri
Case 10
stritemtoenter = strj
Case 11
stritemtoenter = strk
Case 12
stritemtoenter = strl
Case 13
stritemtoenter = strm
Case 14
stritemtoenter = strn
Case 15
stritemtoenter = stro
End Select
Loop
Select Case intnumberofitems
Case 1
ReDim Preserve strlistofitems(0)
Case 2
ReDim Preserve strlistofitems(1)
Case 3
ReDim Preserve strlistofitems(2)
Case 4
ReDim Preserve strlistofitems(3)
Case 5
ReDim Preserve strlistofitems(4)
Case 6
ReDim Preserve strlistofitems(5)
Case 7
ReDim Preserve strlistofitems(6)
Case 8
ReDim Preserve strlistofitems(7)
Case 9
ReDim Preserve strlistofitems(8)
Case 10
ReDim Preserve strlistofitems(9)
Case 11
ReDim Preserve strlistofitems(10)
Case 12
ReDim Preserve strlistofitems(11)
Case 13
ReDim Preserve strlistofitems(12)
Case 14
ReDim Preserve strlistofitems(13)
Case 15
ReDim Preserve strlistofitems(14)
End Select
Array.Sort(strlistofitems)
For Each srtiteminlist In strlistofitems
Me.lstoutput.Items.Add(striteminlist)
Next
End Sub