passing class level variable byref

  • Thread starter Thread starter Cc
  • Start date Start date
C

Cc

hi,
how do I pass byref a variable at class level? , something like how dataset
work,event if declare at class level but it always pass as ref.
 
Hi Cc,

I'm afraid that I don't understand your query. Could you give a few more
details, please?

Regards,
Fergus
 
for example
I have form call form1.vb and class call class1.vb . on class1.vb you have
function A and B . if for example u need to pass a variable byref from
form1 to class1 what we usually do is declare function with parameter
passing byref. this is allright if for 1 or 2 function, but if all function
in class1 required the variable tobe pass as ref this could be tedious when
everytime calling the function in class1. that why i ask is there better
solution in this.
 
Cc said:
for example
I have form call form1.vb and class call class1.vb . on class1.vb
you have function A and B . if for example u need to pass a
variable byref from form1 to class1 what we usually do is declare
function with parameter passing byref. this is allright if for 1 or 2
function, but if all function in class1 required the variable tobe
pass as ref this could be tedious when everytime calling the function
in class1. that why i ask is there better solution in this.

I hope I understood you right. First, you only need to pass the Form "ByRef"
if you want to create a *new* Form in class1. If you don't create a new Form
in Class1, pass the Form ByVal. Second, why don't you write the code in
Form1?
 
Cc said:
I have form call form1.vb and class call class1.vb .
on class1.vb you have function A and B . if for example
u need to pass a variable byref from form1 to class1 what
we usually do is declare function with parameter
passing byref.

Make sure you understand the difference between 'ByVal' and 'ByRef' for
reference types:

\\\
Public Sub Main()
Dim sb As New StringBuilder("BBB")
changeit1(sb)
MsgBox(sb.ToString())
sb = New StringBuilder("BBB")
changeit2(sb)
MsgBox(sb.ToString())
System.Console.ReadLine()
End Sub

Private Sub changeit1(ByVal s As StringBuilder)
s = New StringBuilder()
s.Append("Bla")
End Sub

Private Sub changeit2(ByRef s As StringBuilder)
s = New StringBuilder()
s.Append("Bla")
End Sub
///
 
Hi Cc,

|| but if all function in class1 required the variable
|| to be pass as ref this could be tedious when
|| everytime calling the function in class1.

I'm not sure what's tedious about it? Is it too much to type ByRef in your
parameter list ?

However, if the variable that you are passing is an object of any sort, it
is <already> a reference variable and wouldn't need ByRef.

Have I understood your query ?

Regards,
Fergus
 
Back
Top