Adding a number(from a textBox) to a list box

vb6 Ireland
  • 14 years ago

    Hi Folks,

    I am trying to create a small vB program that the user can enter a number in a text box and then add it to a list box.

    Click Add to add this number to a list of numbers (a list box).

    Click Remove to remove a selected number from the list of numbers.

    Click Remove All to remove all numbers from the list

     

    Validation

    •         When adding a value to the list, you must validate that the value is actually a number.

    •         If it is not a number, clear the text box and allow the user to enter another number immediately (i.e. put focus back to the text box).

    •         Ensure that clicking Remove does not throw an error if there are no numbers in the list or if nothing is selected in the list.

     

    I seem to be running into problems when trying to add it to the list box. Is this a data type problem.

    Any help would be appreciated!

  • 14 years ago

    Hi,

    Check This

    Private Sub cmdAdd_Click()
    If Me.txtInput <> "" And IsNumeric(Me.txtInput) Then
    Me.lstNum.AddItem Me.txtInput
    Else
    Me.txtInput.SetFocus
    MsgBox "Please enter a number"
    Me.txtInput = ""
    End If
    End Sub







    Private Sub cmdRem_Click()
    If Me.lstNum.ListCount = 0 Then
    MsgBox "There are no items to remove"
    Else
    If Me.lstNum <> "" Then
    Me.lstNum.RemoveItem Me.lstNum.ListIndex
    Else
    MsgBox "Please select an item"
    End If
    End If
    End Sub









    Private Sub cmdRemAll_Click()
    If Me.lstNum.ListCount = 0 Then
    MsgBox "There are no items to remove"
    Else
    Me.lstNum.Clear
    End If
    End Sub







    Hope this works for you.

  • 14 years ago

    Thanks Kassem,

    Worked well(with slight mod), your bush joke was funny tho!

    P

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”