VBAvid
02-27-2002, 07:12 PM
hi everyone, i would like to ask if anyone can explain to me the differences? thanks in advance :)
Differences between Public subroutines and functions in Module and FOrmsVBAvid 02-27-2002, 07:12 PM hi everyone, i would like to ask if anyone can explain to me the differences? thanks in advance :) Volte 02-27-2002, 07:20 PM Private in a form means it can only be accessed from events and controls internal to the Form. Public in a form means it can be accessed from anywhere like this:Form1.Routine Param1, Param2, Etc Private in a module means that the routine can only be accessed from other routines inside that module. Public in a module means that the routine can be accessed from any form, module, class, whatever in the entire project, without even needing to specify the module's name:Routine Param1, Param2, Etc There is also another keyword, Friend, used in classes. Friend in a class means that the function can be accessed from all the forms, modules, etc in the DLL (or the Class's project) without being fully public to all forms. ClassProject --- Class1 --- Form1 --- Module1 <=== Friend function declared here ClassInstancep --- TestForm --- TestModule Green means that the function can be accessed from there. Bucky 02-27-2002, 07:22 PM Subs just do their commands whenever they're called. It can save code if you want to call the same commands from, say, from a command button and a menu item. Functions are just like subs, but they return a value. I could create a function to reverse a string, for example, like this: Function reverseString(strString As String) As String Dim i As Integer For i = Len(strString) To 1 Step -1 reverseString = reverseString & Mid$(strString, i, 1) Next i End Function See how the name of the function acts just like a variable? Then I would use it like this: Dim x as String x= reverseString("Cows rule!") MsgBox x That'd give the the msgbox that says "!elur swoC". Does that make sense? I'm not too good at 'splaining... :) |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum