ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   names of variables in array (https://www.excelbanter.com/excel-programming/425267-names-variables-array.html)

David

names of variables in array
 
I am using a set of keywords to get data from a batch of text files
i can load the keywords into an array at the start of the program
and then use each one to sequentially search each text file in turn
Can I convert the array contents to names of variables and vice-verca?
(Would make code very compact)

Dim kwd1 As Double, kwd2 As String
myarr = Array("kwd1", "kwd2")
ConvertedToVariableName(myarr(0)) = 50.1
ConvertedToVariableName(myarr(1)) = "mystring"
MsgBox kwd1 'returns value 50.1
MsgBox kwd2 'returns string "mystring"


Nigel[_2_]

names of variables in array
 
I think you would be better using a collection, they provide an indexed set
of values, you can control how the data is manipulated. Also collections do
not allow duplicate keys something that would be an issue if not controlled.

--

Regards,
Nigel




"David" wrote in message
...
I am using a set of keywords to get data from a batch of text files
i can load the keywords into an array at the start of the program
and then use each one to sequentially search each text file in turn
Can I convert the array contents to names of variables and vice-verca?
(Would make code very compact)

Dim kwd1 As Double, kwd2 As String
myarr = Array("kwd1", "kwd2")
ConvertedToVariableName(myarr(0)) = 50.1
ConvertedToVariableName(myarr(1)) = "mystring"
MsgBox kwd1 'returns value 50.1
MsgBox kwd2 'returns string "mystring"



David

names of variables in array
 
Thanks Nigel
Ok, I'll store my keywords as collection items
Say I have an item, "myABCkeyword" and I use it to search out a line of
data from a text file.
Once I find the data I want to assign the data to a variable called
"myABCkeyword" or something like "_myABCkeyword" (ie: "_" & itemname). Can I
force the item name (or "_" & itemname) to become the name of a variable?
Thanks Again

"Nigel" wrote:

I think you would be better using a collection, they provide an indexed set
of values, you can control how the data is manipulated. Also collections do
not allow duplicate keys something that would be an issue if not controlled.

--

Regards,
Nigel




"David" wrote in message
...
I am using a set of keywords to get data from a batch of text files
i can load the keywords into an array at the start of the program
and then use each one to sequentially search each text file in turn
Can I convert the array contents to names of variables and vice-verca?
(Would make code very compact)

Dim kwd1 As Double, kwd2 As String
myarr = Array("kwd1", "kwd2")
ConvertedToVariableName(myarr(0)) = 50.1
ConvertedToVariableName(myarr(1)) = "mystring"
MsgBox kwd1 'returns value 50.1
MsgBox kwd2 'returns string "mystring"





All times are GMT +1. The time now is 03:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com