Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array problem

Status
Not open for further replies.

QatQat

IS-IT--Management
Nov 16, 2001
1,031
IT
Hi There,

I am trying to create an array that stores excel cells and their value.

Can I store multiple values (cell-name and value) per each of the array indexes

Example:

array(0) = B3, 100
array(1) = C8 , 140
etc.

If not possible what is the best way to achieve this?


Thanks a lot

QatQat



Life is what happens when you are making other plans.
 
Two ways:

1st
Create a 2-dim array. Many rows and 2 columns.
array(0,0)="b3"
array(0,1)="100"
array(1,0)="c8"
array(1,1)="140", etc

Note that i put quotes. Why? -> dim array(100,2) as string. Any array must contain values from the same data type. To handle then the string "100" as a number, simply use: cint(), like cint(array(0,1)).


2nd
1-dim array (string again), but now seperate them by e.g. "|" or any unused char.

array(0)="b3|100"
array(1)="c8|140", etc

To get any item use the split().
-E.g. :
dim x as string
x=split(array(0), "|")
x(0) has "b3"
x(1) has "100"

Same way use cint(x(1)) to perform mathematical operations.


Hope these help
 
You can also create your own data type and store them in the array.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Or make your own data type and store it in a collection. Or if one or the other pieces of data should be unique and you want a good way to store the data and ensure/check uniqueness, I would use a dictionary.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top