Tip

How to make a 'quick and dirty' array

This tip illustrates how can you quickly create an array by using the evaluate command.
Dim evalString As String
Dim myVar As Variant
Dim i As Integer

evalString = {"A":"B":"C":"D"}
myVar = Evaluate(evalString)

'Creates an array of strings where
'myVar(0) = "A"
'myVar(1) = "B"
'myVar(2) = "C"
'myVar(3) = "D"

Msgbox {The string "} & evalString & {" when Evaluate'd gives the 
following values} For i = Lbound(myVar) To Ubound(myVar) Msgbox "myVar(" & Cstr(i) & ") = """ & myVar(i) & """" Next 'Similarly evalString = {1:2:3:4} myVar = Evaluate(evalString) 'Creates an array of numbers where 'myVar(0) = 1 'myVar(1) = 2 'myVar(2) = 3 'myVar(3) = 4 Msgbox {The string "} & evalString & {" when Evaluate'd gives the
following values} For i = Lbound(myVar) To Ubound(myVar) Msgbox "myVar(" & Cstr(i) & ") = " & myVar(i) Next
Please visit our website http://www.novadata.com/ID=RMES-586NYN for more tips.

This was first published in March 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.