[RESOLVED] Decalring global variables in VBA
Hi, I am quite new to VBA and i wan to know how can i declare a global variable in VBA. I understand tat i need to put this definition in a module, something like header files in C.. but what else is require in the module?
can someone pls help me by giving me exactly the codes for declaring a golbal variable in a module?
Global Variable : toolPath
Type : String
so do i define as Public toolPath As String?? anything esle n where to place it? thks
btw, i am using VBA in access... so the "lifespan" of the variable will last till the entire application is closed right?
thks
Re: Decalring global variables in VBA
You have yourself answered your question.
You add a module in your VBA project and then write
VB Code:
Public toolPath As String
This makes the variable available to all other modules.
Re: Decalring global variables in VBA
Quote:
Originally Posted by Shuja Ali
You have yourself answered your question.
You add a module in your VBA project and then write
VB Code:
Public toolPath As String
This makes the variable available to all other modules.
thks.. wats the difference between a module and a class module?
Re: Decalring global variables in VBA
Re: Decalring global variables in VBA
wat if i want a function to return a value? how can i declare it?
Eg Function Name =
Private Sub Test()
i want it to return a string. how can i do it? thks...
Re: Decalring global variables in VBA
A Sub does not return anything at all. A Function does.
VB Code:
'In a standard Module:
Option Explicit
Public Function AnimalSound() As String
AnimalSound = "Meow.NET"
End Function
VB Code:
'Usage:
Private Sub Command1_Click()
MsgBox AnimalSound ' "Meow.NET"
End Sub
Re: Decalring global variables in VBA
Class Module : It is basically a template using which objects can be created. The code that is written in the class module basically describes the attributes (methods, events, properties, fields) of the object that are created using that class module. Class modules are the foundation of OOP in VB.
Module: MOdules are basically the files where you write common procedures and declare public data that will be accessed throughout the application.
Re: Decalring global variables in VBA
got it.. thks to the both of u :)