Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8657683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:34:56+00:00 2026-06-12T15:34:56+00:00

I have some const in a VBA module but I would like to put

  • 0

I have some const in a VBA module but I would like to put them in a INI file because I have other applications that use the same constants. This works:

Public Const PATH_DB As String = "\\server\folder\bdd.mdb"

This however doesn’t work:

Public Const PATH_DB As String = getFromIni("path","db","C:\config.ini")

Public Function getFromIni(ByVal strSectionName As String, ByVal strEntry As String, ByVal strIniPath As String) As String
    Dim x As Long
    Dim sSection As String, sEntry As String, sDefault As String
    Dim sRetBuf As String, iLenBuf As Integer, sFileName As String
    Dim sValue As String

    sSection = strSectionName
    sEntry = strEntry
    sDefault = ""
    sRetBuf = Strings.String$(256, 0) '256 null characters
    iLenBuf = Len(sRetBuf$)
    sFileName = strIniPath
    x = GetPrivateProfileString(sSection, sEntry, "", sRetBuf, iLenBuf, sFileName)
    sValue = Strings.Trim(Strings.Left$(sRetBuf, x))

    If sValue <> "" Then
        getFromIni = sValue
    Else
        getFromIni = vbNullChar
    End If
End Function
# C:\config.ini
[path]
db=\\server\folder\bdd.mdb

My getFromIni function actually works pretty well but not when I want to declare constants (it doesn’t compile at all). I tried a global variable instead but for some reason, it doesn’t work either, the variable cannot be found when used from another form in the same project (it only works when it’s declared as a const, but I can’t declare it as a const when getting the value from a function).

What’s wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:34:57+00:00Added an answer on June 12, 2026 at 3:34 pm

    Change

    Public Const PATH_DB As String = getFromIni("path","db","C:\config.ini")
    

    to

    Public PATH_DB As String 
    

    Place the following call that gets the value from INI file in a initialize method (say Database Open event)

    PATH_DB = getFromIni("path","db","C:\config.ini")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that looks like: static const std::string and( AND ); This
I have some simple static array defined in c-file ( const int data_input[1024]; )and
Say I have a class with some const reference member variable and I would
We have some code in spatialite that looks like: static int cmp_pt_coords (const void
I have some class, like class object { public: virtual std::string name() const; };
I have some struct: struct A { const char* name_; A* left_; A* right_;
I have the following string: const char *str = \This is just some random
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some tables roughly like so: Client: id name Employee id name Email
I put together some VBA code for Outlook 2007 which has been working predominantly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.