Results 1 to 9 of 9

Thread: Need help creating a program

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    2

    Need help creating a program

    I need to create a program that will allow me to enter 10 numbers into a list box through a input box. I need to use a For...Next loop to take in 10 numbers, adding each as they entered into the list box. Please help.

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Need help creating a program

    What have you done so far?

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    2

    Re: Need help creating a program

    This is what i have so far. I can't figure out how to get the data i enter in the input box to show up in the list box?

    Private Sub mnuEnterNumbers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEnterNumbers.Click
    Dim userInput As String
    Dim x, total As Integer
    total = 0
    For x = 1 To 10
    userInput = InputBox("Enter a number.", "Input Needed")
    total += x
    Next x
    'lstNumbers = userInput
    End Sub

    Please help.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need help creating a program

    We can't do your homework for you and if this is an exercise from a book you're using then there's not much point us doing it for you as you learn by doing. The rule to programming problems, as for most problems, is to divide and conquer. Don't look at the whole problem, but rather break into manageable pieces. Once you solve each subproblem you automatically solved the whole.

    First things first. Can you use an InputBox to get a string from the user?

    Then, can you put a string in a ListBox?

    Then, can you make a For loop do the same thing 10 times?

    Note that those three things are completely unrelated. They are all independent problems but if you can solve them then you can put the result together to solve your original problem.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need help creating a program

    If you want to add and item to a ListBox you call the Add method of the LisBox's Items property:
    VB Code:
    1. myListBox.Items.Add(newItem)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Need help creating a program

    Just a tip if surround your code with VBCODE & /VBCODE tags it easier to read your code.
    VB Code:
    1. listBox1.Items.Add(userInput)

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  7. #7
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Need help creating a program

    Here it comes
    VB Code:
    1. Private Sub mnuEnterNumbers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEnterNumbers.Click
    2.         Me.lstNumbers.Items.Clear()
    3.         For i As Integer = 1 To 10
    4.             Me.lstNumbers.Items.Add(InputBox("Enter a number.", "Input Needed"))
    5.         Next i
    6.     End Sub
    Edit** as shown above.

  8. #8
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Need help creating a program

    Jmcilhinney got 3 post in before I got 1 - speed racer!!!

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need help creating a program

    Everyone here got a life in before I got any.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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