What are the 3 basic functions of social work?

How Do Functions Work in Visual Basic 2010?

  • I am trying to learn Visual Basic dot Net. I've learned about data types, how to declare variables and formatting dates. The text I'm reading has now moved on to Methods and discusses subroutines and Functions. I understand that Methods of the subroutine variety do not return a value while methods of the function variety do. I understand how to define and call a method. What I am totally stuck on is a particular function that is part of an exercise used in the text. This method returns a value therefore making it a function and stores it in a variable. In the subroutine that calls the function, another variable has been declared to hold the same result in the function. I know this because the MessageBox.Show method extracts the value from the variable in the subroutine and displays it. I don't understand how the value of a variable in the function was transferred to the variable in the subroutine for display by MessageBox.Show. I have attached the code below. Please explain this to me. It is driving me crazy. Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Declare variable Dim dblArea As Double 'Calculate the area of a cirle with a radius of 100 dblArea = CalculateAreaFromRadius(100) 'Display the Results MessageBox.Show(dblArea.ToString, "Area of 100") End Sub 'CalculateAreaFromRadius-find the area of a circle Private Function CalculateAreaFromRadius(ByVal radius As Double) As Double 'Declare Variables Dim dblRadiusSquared As Double Dim dblResult As Double 'Square the Radius dblRadiusSquared = radius * radius 'Multiply it by PI dblResult = dblRadiusSquared * Math.PI 'Return the Result Return dblResult End Function End Class

  • Answer:

    'Calculate the area of a cirle with a radius of 100 dblArea = CalculateAreaFromRadius(100) Here you are calling the function (CalculateAreaFromRadious) and passing it the value of 100. You can even write the name of a variable here. The variable dblArea will = the value which will be returned from the function. 'CalculateAreaFromRadius-find the area of a circle Private Function CalculateAreaFromRadius(ByVal --> radius <-- As Double) As Double The variable radius holds the number 100 which was passed to it. You do your calculations to the variable radius and return the variable dblResault to dblArea. dblResult = (radius * radius) * Math.PI Think this would work too, you dont need to have two variables.

theman10... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

How does the value of a variable in the function get transferred to the variable in the subroutine? The short answer is, it just does. This whole chapter in my book confused the hell out of me as well, and that was basically my teachers answer after trying to explain it to me other ways. Take the example below..When the function AddtheNumbers is called in the Button1 click procedure the numbers num1 (which is the number entered by the user) is passed into the position of differentName1. This number is then used by the function DoubleTheNumber to do just that. It doubles the number and then sends that (Returns) the calculation so that something else can be done. In this case it is being displayed in TextBox1. In your example the variable named "radius" could be changed to anything. Just as in the example below the variable named differentName1 could be changed to anything. Once the function CalculateAreaFromRadius is called in your click procedure, radius is replaced with 100, and the calculations performed in the function procedure now are using 100. In my example when DoubleTheNumber is called, whatever number the user enters into the text box now replaces differentNum1, and that is the number being used for the calculations. Again, the short answer is that's just how functions work. Note though that I wouldn't use DoubleTheNumber(differentNumber1) in the click procedure, I use DoubleTheNumber(num1). Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim num1 As Double = CDbl(TextBox1.Text) TextBox1.Text = CStr(DoubleTheNumber(num1)) End Sub Function DoubleTheNumber(ByVal differentName1 As Double) As Double Dim num2 As Double = differentName1 * 2 Return num2 End Function End Class

Navin R. Johnson

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.