please give an example of a class module.

M

Mike

someone please explain how to create a class in VBA
eg class named swap
Public swapdb As clsswap
Private m_number As Byte
Private m_units, m_notional, m_libor, cvalue As Double
Private m_name, m_ticker As String
Private m_td, m_exdate, m_r1, m_r2, m_r3, m_r4 As Date





Public Property Get addnumber() As Double
addnumber = m_number 'new swap #
End Property

Public Property Let addnumber(ByVal newnumber As Double)
m_number = newnumber
End Property
Public Property Get addunits() As Double
addunits = m_units 'new swap units
End Property

Public Property Let addunits(ByVal newunits As Double)
m_units = newunits
End Property
Public Property Get addname() As String
addname = m_name 'new swap name
End Property

Public Property Let addname(ByVal newname As String)
m_name = newname
End Property
Public Property Get addticker() As String
addticker = m_ticker 'new swap ticker
End Property

Public Property Let addticker(ByVal newticker As String)
m_ticker = newticker
End Property
Public Property Get addnotional() As Double
addnotional = m_notional 'new notional amount
End Property

Public Property Let addnotional(ByVal newnotional As Double)
m_ticker = newnotional
End Property
Public Property Get addlibor() As Double
addlibor = m_libor 'new libor rate
End Property

Public Property Let addlibor(ByVal newlibor As Double)
m_libor = newlibor
End Property
Public Property Get addtd() As Date
addtd = m_td 'trade date
End Property

Public Property Let addtd(ByVal newtd As Date)
m_td = newtd
End Property
Public Property Get addexdate() As Date
addexdate = m_exdate 'expiration date
End Property

Public Property Let addexdate(ByVal newexdate As Date)
m_exdate = newexdate
End Property
Public Property Get addr1() As Date
addr1 = m_r1 'reset date1
End Property

Public Property Let addr1(ByVal newr1 As Date)
m_r1 = newr1
End Property
Public Property Get addr2() As Date
addr2 = m_r2 'reset date2
End Property

Public Property Let addr2(ByVal newr2 As Date)
m_r2 = newr2
End Property
Public Property Get addr3() As Date
addr3 = m_r3 'reset date3
End Property

Public Property Let addr3(ByVal newr3 As Date)
m_r3 = newr3
End Property
Public Property Get addr4() As Date
addr4 = m_r4 'reset date4
End Property

Public Property Let addr4(ByVal newr4 As Date)
m_r4 = newr4
End Property

Dim i As Byte
'i = 1
Public swapi As New swapdb

Public Sub addswap()
swapi.addnumber = Range("b2")
swapi.addname = Range("b4")
swapi.addtd = Range("b6")
swapi.addexdate = Range("b8")
swapi.addunits = Range("b10")
swapi.addnotional = Range("b12")
swapi.addlibor = Range("b14")
swapi.addticker = Range("b16")
swapi.addr1 = Range("b18")
swapi.addr2 = Range("b20")
swapi.addr3 = Range("b22")
swapi.addr4 = Range("b24")
end sub

what am i missing?

Thanks
 
P

Patrick Molloy

be careful with your DIM statements!
You have

Private m_units, m_notional, m_libor, cvalue As Double
Private m_name, m_ticker As String
Private m_td, m_exdate, m_r1, m_r2, m_r3, m_r4 As Date

in this you assume m_units is double and mlibor is
Double. They are not, you have defaulted them to Variant.
M-name is variantand only the last date is Date.

You should have

Private m_units As Double, m_notional As Double, m_libor
As Double, cvalue As Double
Private m_name As String, m_ticker As String
Private m_td As Date, m_exdate As Date, m_r1 As Date,
m_r2 As Date, m_r3 As Date, m_r4 As Date


Patrick Molloy
Microsoft Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top