Question

In: Computer Science

Im just having some trouble using functions in visual basics. Could you please explain what Im...

Im just having some trouble using functions in visual basics. Could you please explain what Im doing wrong? I think it has to do with the calling of the function.

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Close()

    End Sub

    Private Function Rsumation(ByVal intx As Integer) As Double
        intx = CInt(Txtinput.Text)
        If intx = 1 Then
            Return 1
        Else Return (intx + Rsumation(intx - 1))

        End If
    End Function

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MessageBox.Show(CStr(Rsumation(CInt(Txtinput.Text)).ToString("N2")))
    End Sub


End Class

Solutions

Expert Solution

Application Name :RsumationApp

Language Used :VB

User Interface :Form2.vb[Design]

Code :Form2.vb

Public Class Form2 'VB Class
'Button 1 click
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close() 'close form
End Sub
'Function
Private Function Rsumation(ByVal intx As Integer) As Double
'if intx is 1 then
If intx = 1 Then
Return 1 'return 1
Else
'return
Return (intx + Rsumation(intx - 1))
End If
End Function
'Button 2 click
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Call function and show the result in the messagebox
MessageBox.Show(CStr(Rsumation(CInt(Txtinput.Text)).ToString("N2")))
End Sub
End Class
=================================

Screen 1:

Screen 2:

Screen 3 :


Related Solutions

I have to write a random password generator in Python 3 and im having some trouble...
I have to write a random password generator in Python 3 and im having some trouble writing the code and i dont really know where to start. The prompt goes as such: The problem in this assignment is to write a Python program that uses functions to build (several options of) passwords for the user. More specifically, your program will do the following: 1. Prompt the user for the length of the password to be generated. Call this length lenP....
could you please explain constructive interference and destructive interference I'm having trouble wrapping my brain around...
could you please explain constructive interference and destructive interference I'm having trouble wrapping my brain around it I'm completely lost. thank you
If anyone could simplify this for me. I'm having trouble understanding the material and I just...
If anyone could simplify this for me. I'm having trouble understanding the material and I just need a keep it simple stupid approach Discuss the various non influential as well as influential investments that company may have on their financial statements. Also compare and contrast how they are treated/recorded on the companies financial statements.
Hello, I was having trouble combining two stock data sets into excel. If you could please...
Hello, I was having trouble combining two stock data sets into excel. If you could please select a random stock and S&P 500 and conduct the following A.1) From Yahoo Finance’s Historical Data feature, download 5 years of daily data. The measures include Date, Open, High, Low, Close, Adj Close, and Volume. You should download this data for both your stock as well as for the S&P500. A.2) Combine the data in one Excel sheet. Add a prefix to each...
I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks....
I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks. #include <iostream> #include <string> #include <cstdlib> using namespace std; /* * structure to store employee details * employee details are stored as linked list */ struct Employee { private:    string full_name; //full name    double net_income; //income public:    struct Employee *next; //pointing to the next employee details in the list                        /*                   ...
I am having trouble with the entry to adjust accumulated depreciation, can you please explain.
I am having trouble with the entry to adjust accumulated depreciation, can you please explain.
You are using a microtome but are having trouble cutting the tissue into sections. Which troubleshooting...
You are using a microtome but are having trouble cutting the tissue into sections. Which troubleshooting strategy/strategies would you choose?
BALANCING: Na2SO3 (aq) + H2SO4(aq) PLEASE explain your answer. im fine w balancing, im just confused...
BALANCING: Na2SO3 (aq) + H2SO4(aq) PLEASE explain your answer. im fine w balancing, im just confused with trying to find the reaction formula. i know the answer, i need to know HOW you got it (ive looked everywhere and cant find an explanation for why you get the H20 and the SO2 in the answer)
hello, I'm having trouble understanding how to do these two problems could you show me a...
hello, I'm having trouble understanding how to do these two problems could you show me a step by step. 1)Eight sprinters have made it to the Olympic finals in the 100-meter race. In how many different ways can the gold, silver, and bronze medals be awarded? 2)Suppose that 34% of people own dogs. If you pick two people at random, what is the probability that they both own a dog? Give your answer as a decimal (to at least 3...
I am having trouble writing these queries in MYSQL. Using the schema listed below, please write...
I am having trouble writing these queries in MYSQL. Using the schema listed below, please write the following queries in MYSQL: 1) Find the Content and the Reviewer Name for each comment, about “ACADEMY DINOSAUR” only if the same reviewer has commented about “ACE GOLDFINGER” too. 2) Retrieve the title of all the Movies in Japanese without any comment, ordered alphabetically. 3) Find all the movie titles where an actor called “TOM” or an actor called “BEN" acted, where there...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT