• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Using Wildcards within Variables

patsfan

Member
I am wondering if it is possible to use a wildcard when declaring variables. Example, I need to use "Public ABC1, ABC2, ABC3, ABC4..." statement up to the number 20. Is there a way to use a statement like "public ABC*" which would declare all variables beginning with "ABC"? Along with this, is it possible to clear out ALL declared variables instead of "VBNullString"ing every one? I apologize if I used improper terminology for any of these terms.
 
Hi,


No, you can't declare a bunch of variables like that. The good news is there's a better alternative for you: use an array. If you give a bit more info then we might be able to suggest a bit more on the array (type, scope, dynamic or static, dimensions, etc), but essentially it sounds like you need a 1 dimensional, static, string array variable with 20 elements. Arrays can be cleared using an
Code:
Erase
statement, although the effect is slightly different on dynamic and static arrays (more on that when we know which one you need).
 
Thanks Colin, I appreciate your response but due to IT security settings, I am pretty limited to what I am able to share.


I am beginning to dive into a new realm of Excel VBA for the purpose of reading and imputing fields and values into an “EXTRA.System” system object. This utilizes some code I am not yet familiar with but I have some previously written code to use as a guide. I also do not have the ability to access any of the file sharing sites so frequently mentioned here. The program will require a lot of new code for me to learn. Needless to say, my code is very rudimentary.


The program I am working on involves 20 different variables for 6 different categories. I have included the statements individually “Public ABC1, ABC2, ABC3…ABC20” but was just wondering if there are wildcard options within coding variables that would expand as needed.


Your comment regarding array alternatives is currently beyond my scope of understanding. Are you aware of any online documents which could provide me with more detail about them?


Can you tell me more about the “Erase” statement and it’s uses?
 
Hi, patsfan!


Array definition (100 string variables, 50 integer variables):

Dim sNames(100) as string, iNumbers(50) as integer


Array use:

For I=1 To 100

sNames(I)=""

Next I

For I=1 To 50

iNumbers(I)=0

Next I


sNames(13)="Bad Luck"

iNumbers(19)=12345


Hope it helps. And you still have the built-in help feature available pressing F1 on any selected word from the VBA environment.


Regards!
 
Back
Top