|
-
Jul 29th, 2004, 11:44 AM
#1
Thread Starter
New Member
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.
-
Jul 29th, 2004, 12:23 PM
#2
Thread Starter
New Member
help me please....
I really need a response on this within the next few hours the latest. Thank you.
-
Jul 29th, 2004, 01:40 PM
#3
Frenzied Member
Can you post what you've tried so far? If you have a specific problem, I'm sure you'll get some help.
-
Jul 30th, 2004, 12:16 AM
#4
Member
factorial function
VB Code:
Function factorial(ByVal number As Integer) As Long
If number > 0 Then
factorial = number * factorial(number - 1)
ElseIf number = 0 Then
Return 1
End If
End Function
-
Jul 30th, 2004, 12:58 AM
#5
Fanatic Member
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear() ' clearing
Dim n As Integer
Try
n = Integer.Parse(TextBox1.Text)
Catch ex As Exception
MessageBox.Show("casting exception")
Exit Sub
End Try
If n < 1 Then
MessageBox.Show("bullet proof") ' bullet proof
End If
' i assume you put the result to last item of the listbox
ListBox1.Items.Add(factorial(n))
End Sub
Function factorial(ByVal n As Integer) As Integer
If n > 0 Then
factorial = n * factorial(n - 1)
ListBox1.Items.Add(n)
ElseIf n = 0 Then
Return 1
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|