Results 1 to 4 of 4

Thread: Arrays

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    7

    Arrays

    When I click the Add button is saves the word entered to an array and then when Show is clicked it shows the words in the array. However if I enter 5 words and then click show it'll show the 5 words and then if I add another few words and click show it'll only show the few added words and not the 5 original words entered.

    Code:
    Public Class Form1
    
        Dim wordList(19) As String
        Dim k As Integer
    
    
        Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
    
    
    
            If k < 20 Then
                wordList(k) = txbWord.Text
            End If
    
            If k = 19 Then
                cmdAdd.Enabled = False
            End If
    
    
    
            k = k + 1
    
    
    
    
    
    
    
    
    
            ' txbWord.Clear()
            ' doesnt include 20th word in list
    
        End Sub
    
        Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShow.Click
    
    
    
            lstBox.Items.Clear()
    
            Array.Sort(wordList)
    
            Dim i As Integer
    
            lstBox.Items.Add("Index  Word")
    
            For i = 0 To wordList.GetUpperBound(0)
                lstBox.Items.Add(CStr(i+1) & "          " & wordList(i))
            Next
    
        End Sub
    The array has a limit of 20 words
    Last edited by ryan1234; Nov 18th, 2011 at 11:44 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width