Results 1 to 5 of 5

Thread: I really need help with a vb question....

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    4

    I really need help with a vb question....

    I'm a newbie in programming so I'm kinda confused on how to do this:

    msg me asap:[email protected](msn messenger) I am online as we speak.

    it says:

    Create a program with one textbox called txtnum and a listbox called lstresult. the textbox will be used to capture a positive integer greater than zero and after a button called btncacfactorial is clicked, the list box will be used to display that number's factorial. For example, if the user entered 3 in the textbox and then clicked the button, 6 (which is 3*2*1)shoudl be displayed in the lsitbox. Be sure to clear the listbox before you output the factorial for each number entered. ALso, bullet proof your program to allow only positive integers greater than zero; if the user does not enter a valid entry, give the user an appropriate message box.

    I really need help on this. I have made the layouts with the textbox and listbos and the command button, but i desperately am lost on the coding, please help me.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    4

    help me please....

    I really need a response on this within the next few hours the latest. Thank you.

  3. #3
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Can you post what you've tried so far? If you have a specific problem, I'm sure you'll get some help.

  4. #4
    Member
    Join Date
    Aug 2003
    Posts
    51
    factorial function

    VB Code:
    1. Function factorial(ByVal number As Integer) As Long
    2.         If number > 0 Then
    3.             factorial = number * factorial(number - 1)
    4.         ElseIf number = 0 Then
    5.             Return 1
    6.         End If
    7.     End Function

  5. #5
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.       ListBox1.Items.Clear()  ' clearing
    3.       Dim n As Integer
    4.       Try
    5.          n = Integer.Parse(TextBox1.Text)
    6.       Catch ex As Exception
    7.          MessageBox.Show("casting exception")
    8.          Exit Sub
    9.       End Try
    10.       If n < 1 Then
    11.          MessageBox.Show("bullet proof")   '  bullet proof
    12.       End If
    13.       '  i assume you put the result to last item of the listbox
    14.       ListBox1.Items.Add(factorial(n))
    15.    End Sub
    16.  
    17.    Function factorial(ByVal n As Integer) As Integer
    18.       If n > 0 Then
    19.          factorial = n * factorial(n - 1)
    20.          ListBox1.Items.Add(n)
    21.       ElseIf n = 0 Then
    22.          Return 1
    23.       End If
    24.    End Function
    next time mate, could you post even a little code. we just assume about this one.

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