Public Sub Hello(ByVal name As String, byref answer as string)
answer = String.Format("Hello {0}.", name)
End Sub
Public Sub Hello(ByVal name As String)
myAnswer = String.Format("Hello {0}.", name)
End Sub
Private myAnswer As String
Public Property Answer() As String
Get
Return myanswer
End Get
Set(ByVal value As String)
myAnswer = value
End Set
End Property
Public Sub Hello(ByVal name As String)
myAnswer = String.Format("Hello {0}.", name)
End Sub
Private myAnswer As String
Public Property Answer() As String
Get
Return myanswer
End Get
Set(ByVal value As String)
myAnswer = value
End Set
End Property
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim helloRes As New Hello()
helloRes.Hello("XPTO")
MessageBox.Show(helloRes.Answer)
End Sub
Public Class Hello
Public Sub New()
End Sub
Public Sub Hello(ByVal name As String)
myAnswer = String.Format("Hello {0}.", name)
End Sub
Private myAnswer As String
Public Property Answer() As String
Get
Return myAnswer
End Get
Set(ByVal value As String)
myAnswer = value
End Set
End Property
End Class
Private myInt As Int
Public Property TheNumber() As Integer
Get
Return myInt
End Get
Set(ByVal value As String)
If value = 0 Then Throw New Exception("This property must never be set to zero")
myInt = value
End Set
End Property
If you want a function to return several values, make a special class to hold them. Dont use byref.
public function Hello(byval name as string, byref secondName as string, byref lastName as string) as boolean
public sub Hello(byval name as string)
Realy, have a function that return an instance of a response custom Class. It is the best solution for my project.If you want to return several data you can define a custom class in webservice and return instances of this.
[with ByVal and ByRef [for reference types] you will still operate on the same object even if the pointer references are copies
As I said, that is only valid if the variable is value type, a reference type variable is reference to same object even when there are multiple copies of the reference. Using ByVal parameter on a reference variable just creates a new copy of the reference to the same object. This simple example show this:Remembering, of course, that the most significant thing being that if you change the object that a ByReffed variable points to, the change is retained when the function completes..
Class test
Public member As String
End Class
Sub maketest()
Dim t As New test
t.member = "new"
modifytest(t)
MsgBox(t.member) 'guess what? t object is changed.
End Sub
Sub modifytest([B][U]ByVal[/U][/B] t As test)
t.member = "modified"
End Sub
Class test
Public member As String
End Class
Sub maketest()
Dim t As New test
t.member = "the original test"
modifytest(t)
MsgBox(t.member) 't object is replaced by a whole new one!
End Sub
Sub modifytest([B][U]ByRef[/U][/B] tt As test)
tt = New test()
tt.member = "a whole new test"
End Sub