Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sub, module??

Hi, I'm trying to learn VB within excel, and I'd like to
know what is the difference between a sub and a module, when to use
which
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Sub, module??

Subs are another name for VBA procedures, or macros. These are used to do
something specific.

A module is a container for code, and will contain subs and/or functions.

--

HTH

RP

"Francis Gaudreau" wrote in message
m...
Hi, I'm trying to learn VB within excel, and I'd like to
know what is the difference between a sub and a module, when to use
which



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Sub, module??

A Sub, like a Function, is a type of procedure, or executional unit of code.
Functions return a value in the sense that they can be used on the right of
an assignment statement or as a value in a statement:

Sub Main
Dim x as Long
Dim y as Long
Let x = 12

Let y = AtMost10(x)
Call Msgbox(Cstr(y))
'or just
Call Msgbox(AtMost10(x))

End Sub

Function AtMost10(x as Long) As Long
'limits x to 10
If x 10 Then x = 10
'assign the return value to the fucntion name
AtMost10 = x
End Function

A Sub cannot return values in this way. This is the principal difference
between the two, although their arguments can be modified. Subs contain a
logical collection of steps in a process. By convention, a Sub named Main is
often the startup procedure for an entire program, though this is not
necessary in VBA.

A module is a collection of code, that will include one or more procedures
and/or variable declarations. In many languages, modules are stored as
separate files. Which procedures and variables go into which modules is to
some extent a matter of organizational preference, although some
limitations, requirements, and conventions apply.

Modules come in several forms: Standard, Class, Form, Sheet, Workbook,
others perhaps. Form, Sheet, Workbook, and others are specialized Class
modules. Standard modules can contain private or public Subs, Functions or
variables. Class modules are used to create a Class which is a potentially
complex software object. Unlike Standard modules, classes can include event
handlers, which are procedures (e.g., Sub Command1_Click) called by the
environment in response to some action that took place, like the mouse click
of a button or the tick of a clock.

"Francis Gaudreau" wrote in message
m...
Hi, I'm trying to learn VB within excel, and I'd like to
know what is the difference between a sub and a module, when to use
which



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
Module Monty Excel Discussion (Misc queries) 4 May 19th 05 08:34 AM
arrays - module to module mike Excel Programming 3 February 25th 04 08:56 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 02:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"