Re: friend functions in vb??
A Friend function is always a function in a class. It's concept is about scope.
A friend function is visible to any callee inside the project of where it exists; it cannot be seen, nor called, outside the compilation unit (ActiveX DLL for instance)
Re: friend functions in vb??
Quote:
Originally Posted by yrwyddfa
A Friend function is always a function in a class.
According to the VB Help file, it can be used in a form module as well.
Quote:
Originally Posted by VB Help File
Modifies the definition of a procedure in a form module or class module to make the procedure callable from modules that are outside the class, but part of the project within which the class is defined. Friend procedures cannot be used in standard modules.
Friend is used when you want a property or method to be available to other objects in your project but not to the project as a whole. Does that make sense?
Re: friend functions in vb??
I didn't realise they could be in modules? What purpose does that serve? A public function in a module is only visible inside the project anyway, so a friend function is pretty much the same thing.
Re: friend functions in vb??
hmmm... interesting so does that mean if a designate a sub as a protected one even other subs in the same module will not be able to access it ??
does this make sense?
p.s i understood the concept of friend functions ,thanks hack and vrwy.... !!
Re: friend functions in vb??
VB6 does not have the concept of 'protected' but .Net does (I believe) . . . . :confused:
Re: friend functions in vb??
Quote:
Originally Posted by yrwyddfa
I didn't realise they could be in modules?
Actually, until I looked Friend up in the Help file I didn't either.
Quote:
Originally Posted by yrwyddfa
What purpose does that serve?
Beats the heck out of me. Maybe someone else knows.
Re: friend functions in vb??
and what else does vb have ? operator overloading ,inheritance ? would be really interesting if it does have
Re: friend functions in vb??
source:
http://www.pgacon.com/visualbasic.ht...iend%20Keyword
When writing property procedures and methods for a VB class there are three keywords you can use to control access to the property or method. Two of these are straightforward and easy to understand:
Public. There are no restrictions on access.
Private. The property or method is available only from within its own class.
The third keyword is Friend, and its use and meaning are not well understood. You use Friend when you want a property or method to be accessible to other objects in the project but not to the project as a whole. Or, within a component, objects can access each other's Friend members but the program that is using the component cannot.
Suppose you are writing a component as a DLL or ActiveX, and there are several objects in the component that need to communicate with each other. However you do not want this communication channel to be available to the program that is calling the component. This is perhaps the most common use of Friend properties and methods.
Friend properties and methods are not part of a class's interface. They do not appear in the type library of the class and they are not included when you implement an interface using the Implements keyword.
Re: friend functions in vb??
Example: If you have an UDT declared in a module like this..
VB Code:
Public Type myUDT
var1 As String
var2 As Integer
End Type
And you want to use it as a returned value from a Public Function in a Class..
VB Code:
Public Function getUDT() As myUDT
Dim s As myUDT
s.var1 = "hi"
s.var2 = 1
getUDT = s
End Function
Then, when you try to call that function from where you instanciated your object.. (example, from a Form)
VB Code:
Private Sub Command1_Click()
Dim typ As myUDT
Dim MyObj As Class1
Set MyObj = New Class1
typ = MyObj.getUDT
End Sub
With that you see this..
Code:
Compile error:
Only public user defined types defined in public object modules can be used
as parameters or return types for public procedures of class modules or as
fields of public user defined types
To fix it, you need to declare Function getUDT in the class, as Friend:
VB Code:
Friend Function getUDT() As myUDT
Dim s As myUDT
s.var1 = "hi"
s.var2 = 1
getUDT = s
End Function
That way it knows myUDT is declared public in a module, and picks up its declaration succesfully from there.
Re: friend functions in vb??
that clears my all my doubts
thanks jcis
Re: friend functions in vb??
Quote:
Originally Posted by litlewiki
and what else does vb have ? operator overloading ,inheritance ? would be really interesting if it does have
No and no :)
Re: friend functions in vb??
Quote:
Originally Posted by Hack
Actually, until I looked Friend up in the Help file I didn't either.Beats the heck out of me. Maybe someone else knows.
Friend means you can access it from within your own application only. Anyone else creating a copy of your objects outside (createobject for example) can only access those methods you called Public.
PS: Ive only tried it in .Net.
--
@litlewiki and what else does vb have ? operator overloading ,inheritance ? would be really interesting if it does have
Get vb.net !!