+ Reply to Thread
Results 1 to 9 of 9

Value of Public Constant From Concatenate strings

  1. #1
    Forum Contributor
    Join Date
    07-20-2012
    Location
    Kingdom of Saudi Arabia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Value of Public Constant From Concatenate strings

    Hi,

    i have these public constants:

    Please Login or Register  to view this content.
    and this sub:

    Please Login or Register  to view this content.
    when i call ShowPage sub by

    Please Login or Register  to view this content.
    i Get: (Sh10PegRows , Sh11PegRows).

    How can I get the value of constants (100, 200) instead of the strings?

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Value of Public Constant From Concatenate strings

    First question: why?

    You would need to use a class module with the constants in, then create an instance of the class so that you can use CallByName and pass the name of the constants as strings.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    07-20-2012
    Location
    Kingdom of Saudi Arabia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Re: Value of Public Constant From Concatenate strings

    Hi, romperstomper:

    thank you for your replay...

    these classes modules is just for describe what i want, which, how can i return the value of pre-defined constant if its name is stored in string variable.

    For example: VarString = "Sh10PegRows" , which: Sh10PegRows is a public constant that has a value, so i want to get the value when i use the VarString in my classes.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Value of Public Constant From Concatenate strings

    Or you could put them in a dictionary or collection and retrieve them by name (key), but then they wouldn't be constants.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Contributor
    Join Date
    07-20-2012
    Location
    Kingdom of Saudi Arabia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Re: Value of Public Constant From Concatenate strings

    Hi, shg

    thank you very much for your replay

    your idea is very good but it takes more time, because i have a lot of pre-defined constants used in a lot of modules, so i need to change the whole structure of my project.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Value of Public Constant From Concatenate strings

    You still didn't say why you would need to do this? (only that you do)

  7. #7
    Forum Contributor
    Join Date
    07-20-2012
    Location
    Kingdom of Saudi Arabia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Re: Value of Public Constant From Concatenate strings

    why i use separated module that contains my constants?

    because i use it in many modules and macros

    So that when i change the value of the constant, it will change in all modules.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Value of Public Constant From Concatenate strings

    You could have a public collection and a routine that initializes it at startup.
    Last edited by shg; 11-13-2014 at 05:02 PM.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Value of Public Constant From Concatenate strings

    Quote Originally Posted by exceere View Post
    why i use separated module that contains my constants?
    No - why you need to refer to them using a string you came up with at runtime.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. creating a public constant by concatenating string......gives compile error
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-26-2011, 07:23 AM
  2. Using a cell value as a public constant
    By larawill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2009, 05:59 AM
  3. Create a public constant that defines a specific RGB color
    By batman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2007, 11:39 PM
  4. concatenate strings
    By Gary''s Student in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-15-2005, 01:05 PM
  5. [SOLVED] How do you update a public constant
    By Greg in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-11-2005, 07:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1