Results 1 to 4 of 4

Thread: text box use to populate array

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    12

    text box use to populate array

    I want to create an application that:
    is a form with a text box and a label

    the text box recieves numeric input (values 1-20)

    then upon pressing the enter key on the key board
    the text in the text box populates a dynamic array, and if the
    value is already there the label displays the value that was
    entered (the duplicate value).

    I know how to set up the GUI but I don't know how to make this work right. Please help as soon as you can. I have a deadline of 6pm Monday July 19th that I have to meet.

    any help is appreciated.

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    perhaps
    VB Code:
    1. Dim a As New ArrayList()
    2.    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    3.       If e.KeyCode = Keys.Enter Then
    4.          If Not isThere(TextBox1.Text) Then
    5.             a.Add(TextBox1.Text)
    6.          Else
    7.             MessageBox.Show(String.Format("{0} is in the ArrayList", TextBox1.Text))
    8.          End If
    9.       End If
    10.    End Sub
    11.  
    12.    Function isThere(ByVal s As String) As Boolean
    13.       Dim o As Object
    14.       For Each o In a
    15.          If s = o.ToString Then
    16.             Return True
    17.          End If
    18.       Next
    19.       Return False
    20.    End Function
    21.  
    22.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    23.       Dim o As Object
    24.       Dim s As String
    25.       For Each o In a
    26.          s &= o.ToString & Constants.vbCrLf
    27.       Next
    28.       MessageBox.Show(s)
    29.    End Sub
    if not, sorry...

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    If I understand you, try

    VB Code:
    1. Dim arrTest(21)  As Boolean   '  Form wide scope
    2.  
    3. Private Sub TextBox1_KeyDown(ByVal sender As Object,
    4.        ByVal e As System.Windows.Forms.KeyEventArgs) Handles
    5.       TextBox1.KeyDown
    6.       If e.KeyCode = Keys.Enter Then
    7.              If arrtest(cint(TextBox1.Text)) = True then
    8.                  Label1.Text=TextBox1.Text
    9.              Else
    10.                  Label1.Text=""
    11.              End If
    12.              arrTest(cint(TextBox1.Text))=True
    13.       End If
    14. End Sub
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    12

    Thanks

    Thanks for the quick response I just had to tweak what you gave me a little to make it work and wa la. I'm new to VB and VB.Net as well so I just needed a little guidance that's all.

    Thanks again,
    tiffjoe

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