highlighting ByVal and when I mouse over, it is displaying expression expected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Garima12
    New Member
    • Mar 2007
    • 58

    #1

    highlighting ByVal and when I mouse over, it is displaying expression expected

    I am writing following code to fetch the data from database, using stored procedure. problem is it is highlighting ByVal and when I mouse over, it is displaying expression expected.
    Please anyone can tell me what is the reason?

    Mapdata is a class which contains the stored procedure SPar.

    Code:
    Dim ds As New DataSet
            Dim objdata As New Mapdata
            ds = objdata.SPar(ByVal Connection As String, ByVal houseNumber As String, ByVal streetAddress As String _
                , ByVal city As String, ByVal zip As String, ByVal taxkey As String) As DataSet
                  DataGridView1.DataSource = ds.Tables(0)
    thks
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    You are getting this error because while calling the function objdata.SPar
    you should not include the keyword ByVal for the parameters you are passing.

    e.g. You should call the function in this way :

    ds = objdata.SPar(Co nnection, houseNumber, streetAddress _
    ,city,zip,taxke y )

    You should only pass the variables to the function while calling it, if the function is accepting any parameter.





    Originally posted by Garima12
    I am writing following code to fetch the data from database, using stored procedure. problem is it is highlighting ByVal and when I mouse over, it is displaying expression expected.
    Please anyone can tell me what is the reason?

    Mapdata is a class which contains the stored procedure SPar.

    Code:
    Dim ds As New DataSet
            Dim objdata As New Mapdata
            ds = objdata.SPar(ByVal Connection As String, ByVal houseNumber As String, ByVal streetAddress As String _
                , ByVal city As String, ByVal zip As String, ByVal taxkey As String) As DataSet
                  DataGridView1.DataSource = ds.Tables(0)
    thks

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Just to provide more information on what Shweta123 was saying:

      ByVal and ByRef are used when you are declaring a function, not when your using it.

      Eg: You would declare a function:
      [code=vbnet]
      Private Function FooBar(ByVal a As String, ByRef b As Integer) As Boolean
      '....
      '....
      End Function
      [/code]

      When you use the function you would call it and pass in the values it expects like so:
      [code=vbnet]
      '....
      Dim myInt As Integer
      Dim myStr As String = "myString",
      Dim myResult As Boolean = FooBar(myStr,my Int)
      '...
      [/code]

      ByVal indicates to the compiler that the value being passed in is not a memory location, whereas ByRef is a pointer to a memory location. Any changes made to a parameter passed into the Function ByRef will be reflected in the calling function as well because you are modifying the value stored in the memory location itself...where as ByVal passes in a copy of the variable so that the function being called will not modify the same variable that exists in the calling function.

      Be aware that ByVal sometimes does actually point to memory locations instead of copying variables. This happens when you pass Objects into functions. The ByVal works on Native data types only.

      You should look into the difference between ByVal and ByRef for a better understanding of how they work.

      But, as for your problem, you don't use these key words when calling the function, only for when you are defining/declaring the function.

      -Frinny

      Comment

      Working...