IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
VB Classic
Search VB Classic Group:

Advanced
-Collapse +Expand VB Classic Store

Prestwood eMagazine

March Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingVB ClassicLanguage Det...   Print This     
  From the March 2016 Issue of Prestwood eMag
 
VB Classic Language Details:
VB Classic Custom Routines (Sub, Function)
 
Posted 11 years ago on 11/11/2008 and updated 1/29/2009
VB Classic Code Snippet:
 A flashcard from our VB Classic Flashcards Library
 A code snippet from our VB Classic Code Snippets Page

KB101601



Languages Focus: Custom Routines

For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.

VB Classic Custom Routines

VB Classic is a non-OOP language with some OOP features. It offers both Subs and Functions. A Sub does not return a value while a Function does. When Subs and Functions are used in a class module, they become the methods of the class.

Syntax Example:
Sub DoSomething(ByVal pMessage As String)
  MsgBox (pMessage)
End Sub
 
Function GetAge(ByRef pFullname As String) As Integer
  GetAge = 7
End Function

VB Classic Sub & function Example

If you define the following sub and funtion:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Subs and Functions
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub DoSomeCode(ByRef pMessage)
    MsgBox (pMessage)
End Sub
Function GetLastDOW(ADate, AWeekDayConst)
    While Weekday(ADate) <> AWeekDayConst
        ADate = DateAdd("d", -1, ADate)
    Wend
   
    GetLastDOW = ADate
End Function

You can call them. For example, the following code is from the click event of a button:

Private Sub Command1_Click()
    DoSomeCode ("Hello3")
    MsgBox "Last Monday was " & GetLastDOW(Date, vbMonday)
End Sub

More Info


Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1237A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101601 Counter
11103
Since 11/11/2008
-
   Contact Us!
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


Go ahead!   Use Us! Call: 916-726-5675 


©1995-2019 Prestwood IT Solutions.   [Security & Privacy]