Thursday, October 28, 2010

In excel vb how would you make an array of images?

I am making an game in excel vb and need to figure out how to make each car part of an array?In excel vb how would you make an array of images?
I'm not sure if this is what you are looking for, but for what it is worth here is something I did. (I have simplified this by taking out all of the game except the rolling dice)

I created a game in Excel with a rolling dice.

I created a sheet called DieList

A1 = Die Roll

B1 = Picture

A2:A7 = 1 through 6

B2:B7 = pictures of dice numbered 1 through 6

I created a sheet called Board

Name one of the cells Die

Copy one of the die pictures from the DieList sheet and past it onto the Board sheet.

Select the picture so that it has the selection circles around it

Type =Picture in the formula bar and press Enter

Select ';Insert';, ';Name';, ';Define...';

Create a new name called ';PictureList'; that refers to

=OFFSET(DieList!$A$1,1,0, COUNTA(DieList!$A:$A)-1,1)

Create a new name called ';Picture'; that refers to

=OFFSET(DieList!$B$2, MATCH(Board!$A$1,PictureList,0)-1,0,1,1)

Now when you change the value of the cell named ';Die';, the picture of the die will change

Next I created a macro to randomly change the value of the die.



Sub Roll()

Randomize

Range(';Die';).Select

ActiveCell.Formula = ';=INT(RAND()*6)+1';

Rolls = Int(Rnd() * 100 + 10)

For x = 1 To Rolls

Calculate

Next x

Range(';Die';).Select

ActiveCell.Value = ActiveCell.Value

End Sub



Right click on the picture of the die and assign the macro Roll to the picture. Now when you click on the die, it will roll.



When you run this macro, the value of Die changes, changing the picture of the die.



Download my example at http://www.productivecomputer.com/files/鈥?/a>



I hope this made some sense to you.

If it does, you might be able to integrate some of these concepts to solve your game problem. I'd love to to have the opportunity to see what you are working on.



For immediate help go to http://www.crossloop.com/PCS_HelpIn excel vb how would you make an array of images?
You can use collection type of object.

It works like an array and you can define names or keys to each part of car.

To declare a collection object, see below:

dim ncol as new collection

dim i as long



for i = 1 to 10

ncol.add partname, partvalue

next i



To call a part or information, you can use number or name of the part.

No comments:

Post a Comment