Can anyone explain me what parameters are ?

Ciduletz1983

Active member
Joined
Oct 10, 2006
Messages
30
Location
Constanta, Romania
Programming Experience
Beginner
I learn vb from these free web tutorials.

http://www.homeandlearn.co.uk/NET/nets9p3.html

They are telling me " Whatever you call your variables in the AddNumbers Sub does not have to be the same names as the calling line. The variable names can be entirely different. But the values in the variables get passed in the order you set them up. In our case the value in the variable first will get passed to the first variable in our AddNumbers Sub; the value in the variable second will get passed to the next variable we set up in our AddNumbers Sub. "



Here take a look at my code..

http://img224.imageshack.us/my.php?image=problemka8.jpg

It can`t understand. They are saying that the variable names must NOT be the same.. It doesn`t work that are not the same. Could anyone enlight me ?! :)
 
It's not saying that they can't be the same. It's just saying that they don't have to be the same. Let's say that you are married, thus at home you are referred to as Husband. If you go to visit your parents you will be known as Son or Daughter. At work you may be known as Manager or Salesman or whatever. These are all simply different ways to refer to you. The same is true in programming. Variables are simply ways to refer to a value or object. The variable may be different in various palces but the value or object that they refer to can still be the same.
 
Here is a the code :

VB.NET:
Private Function AddTwoNumbers(ByVal first1 As Integer, _
    ByVal second1 As Integer) As Integer

        Dim answer As Integer

        answer = first1 + second1

        AddTwoNumbers = answer

    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim first As Integer
        Dim second As Integer
        Dim result As Integer

        first = Val(txtNumber1.Text)
        second = Val(txtNumber2.Text)

        result = AddTwoNumbers(first, second)

        If result = 0 Then
            MsgBox("Please try again ")
        Else
            MsgBox("The answer is " & result)
        End If
    End Sub

My question is: ByVal in my Private Funtion what it does exactly ? It`s some kind of a Dim declaration or what ?
 
Back
Top