Incrementing instances of a class

Ntherrington

New Member
Joined
Apr 27, 2014
Messages
1
I have created a class to record the properties of a foreign currency trade (date, amount, buy/sell, rate, currency. A new instance must be created for each unique rate. I have figured out the if thens to establish when to create a new instance but I have been unable to figure out how to create a automated naming of instances:

for example
EUR1.rate = x
EUR2.rate = y
EUR3.rate = z

but I don't think I can use numbers because I can never know if I will have 0 or 1,000 rates.

i tried using EUR(Z)
'logic
Z = Z + 1

This errors and won't run. Is it possible to put a variable in a variable name or is there a good work around?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
If you Class is named "CurrClass", and you have all your currencies down column A for instance.

you can load up an array which is big enough to have all your currencies in it


Code:
Sub CurrencyRates()

Dim iRow As Integer
Dim myCurrencies() As New CurrClass

iRow = Range("A" & Rows.Count).End(xlUp).Row ' find out how big must your array be

' this is if you have them listed down a column
' if you have them in another array, a recordset or a collection then you can use the ubound of the other array
' or the .Count method of the collection 

ReDim myCurrencies(1 To iRow)

then you can populate the currclass array like this, using a loop or however you prefer

myCurrencies(1).CurrRate = 10.4322
myCurrencies(1).NameOFCurrency = "GBP"

myCurrencies(2).CurrRate = 3.451212
myCurrencies(2).NameOFCurrency = "TWD"





End Sub
 
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top