Type conversion question in vb.net

  • Thread starter Thread starter Ann
  • Start date Start date
A

Ann

Does somebody know why I get a blank string in strA?

"
Option Strict On
Option Explicit On

Public Class Cast
Private Sub FuncA()

Dim strA As String
funcB(CType(strA, Integer))
MsgBox(strA)

End Sub

Public Sub funcB(ByVal objA As Integer)
objA = 1234
End Sub

End Class

"
 
You are passing it byval instead of by ref. strA never gets changes in
funca.

Byval is the preferred and default way to pass objects. What you should do
is make funcb a function that returns value back to funca

Private Sub FuncA()
Dim strA As integer
a=funcB()
MsgBox(strA.tostring())
End Sub

Public function funcB() as integer
return 1234
End function
 
I did try byref. but the result is the same. I believe if
use ctype in the function parameter, DotNet create a
another object instead of using the original one. --
That's why I always get NULL come back.
 
Back
Top