Subroutine not returning any values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kjell Weding

    #1

    Subroutine not returning any values

    I have this code in VB.NET (VS 2005):

    Module kvitteringFunk
    Public Sub skrivKvittering ()
    Dim KvittPrt As String = ""
    Dim iType As Byte = 0
    KvittPrtType(iT ype, KvittPrt)
    ' iType should now have the value 1 - BUT IS STILL 0!?!?!?!?!?
    ' KvittPrt should now have the value "Common" - but is still
    "".?!?!?!?!
    ....
    End Sub

    Public Sub KvittPrtType(By Val iType As Byte, ByVal KvittPrt As String)
    iType = 1
    KvittPrt = "Common"
    End Sub
    End Module

    Why is my subroutine KvittPrtType not returning any values?????

    Kjell Weding
    Norway


  • Patrice

    #2
    Re: Subroutine not returning any values

    You confused ByVal and ByRef keywords.

    http://msdn2.microsoft.com/en-us/lib...30(VS.71).aspx states :
    "Passing an argument by value means the procedure cannot modify the contents
    of the variable element in the calling code underlying the argument. Passing
    by reference allows the procedure to modify the contents in the same way
    that the calling code itself can."

    You may want to read the language spec at least once.

    --
    Patrice

    "Kjell Weding" <kjell@innlande t-it.noa écrit dans le message de news:
    uAQLxEj5HHA.340 0@TK2MSFTNGP03. phx.gbl...
    >I have this code in VB.NET (VS 2005):
    >
    Module kvitteringFunk
    Public Sub skrivKvittering ()
    Dim KvittPrt As String = ""
    Dim iType As Byte = 0
    KvittPrtType(iT ype, KvittPrt)
    ' iType should now have the value 1 - BUT IS STILL 0!?!?!?!?!?
    ' KvittPrt should now have the value "Common" - but is still
    "".?!?!?!?!
    ....
    End Sub
    >
    Public Sub KvittPrtType(By Val iType As Byte, ByVal KvittPrt As String)
    iType = 1
    KvittPrt = "Common"
    End Sub
    End Module
    >
    Why is my subroutine KvittPrtType not returning any values?????
    >
    Kjell Weding
    Norway
    >

    Comment

    Working...