Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

define value outside module or in an *.ini file

Status
Not open for further replies.

AlexFeddes

Programmer
Jan 17, 2009
22
NL
Hello,
I would like to define text and values 'globally' so that they can be used throughout all modules.

Below is an example of what I want.
Preference would be to define MB1 and MB2 in an outside msgbox.ini file (C:\msgbox.ini) and let the module call for that
'[MsgBox]
'MB1 = "Test 1"
'MB2 = "Test 2"


Function ACF(MsgBox) As Boolean
'This doesn't work yet
MB1 = "Test 1" 'This line I want to get from a global variable so that it is written in the Function, but called up in the various underlying modules
MB2 = "Test 2"

End Function

Sub AA01()
MB1 = "Test 1" 'This line I actually want to get from a global variable (*.ini file) instead of declaring them in each module seperately

MsgBox MB1

End Sub

Sub AA02()

MsgBox MB2

End Sub

Sub AA03()

MsgBox MB1

End Sub

Thank you for looking into this.
Alex
 
It would also help greatly, when posting, if you state what application you are working with.

Word?
Excel?
Access?
Powerpoint?
some other VBA compliant app?

You can probaly go either route. Use a text file (.INI or otherwise), or a global template. It depends.

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 
Hello Gerry,
I've posted it on another forum already - but in any case it is written in Word using VBA.

If you could help me with some simple example, I would be much obliged.

Alex
 
To use a .INI (or other text file in standard Section/Key value format), look up the PrivateProfileString Property in Help.

Here is also a thread that covers this a bit.

Preference would be to define MB1 and MB2 in an outside msgbox.ini file (C:\msgbox.ini) and let the module call for that
'[MsgBox]
'MB1 = "Test 1"
'MB2 = "Test 2"
Code:
System.PrivateProfileString("c:\msgbox.ini", _
   "Msgbox", "MB1")
returns "Test 1".

expression.PrivateProfileString(FileName, Section, Key)

Filename = C:\msgbox.ini
Section = MsgBox
Key = MB1

However, as stated, this is a VBA question and really no longer belongs in the Office forum. If you have further questions, please post to the VBA forum. I will reiterate though, that it still depends on what you are doing. Using an .INi file, or variables in a global template, both methods have their strengths.

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top