by H.M.A.S. Windbag (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 12th November 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Simple Tutorial on how to make a Module.
Normally a module code comprises of:
1. Declarations (Dim, Public and so on)
Most Common Declaration Types:
1. Dim (Normal)
2. Public (Public is like "Oh, I want this particular section to be open
and accessible from other modules or forms.")
2. Public Function # ()
# is where you put the name of the function. The name will be used to access the function from other forms or modules, or in the module itself.
Have you tried making a Message Box? Did you realise that whenever you press "Space" after typing "msgbox", you will see a ToolTip with every data you need to fill? Well, the text of the ToolTip is in the brackets "()". You should type "(your variable name) as (Integer or String or whatever you want it to be)". It should look like this:
Public Function Name (Number1 as Integer)
The data between the brackets is purely optional.
After the first line comes the Function code. It is just like any other procedures. Let's say we want to make a Module that, once called by the Form, will Multiply the Number1 by 7. So we add this:
Number1 = Number1 * 7
Msgbox Number1
End Function (Note: instead of End Sub, we have End Function because it is Public Funciton, not Public Sub or Private Sub!)
That's it. To call the module from ANY form, just type Number1 then enter the number after that.
Happy Coding!