If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Instatiating a class with defualt params

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-20-06, 10:46
MikeroSoft MikeroSoft is offline
Registered User
 
Join Date: Apr 2006
Posts: 47
Instatiating a class with defualt params

I created a class trade and added all my public and private items

i would like the constructor to take 5 params, like :

dim t as new trade(Parm1,Parm2,Parm3)

is this possible with VBA?
Reply With Quote
  #2 (permalink)  
Old 06-20-06, 11:17
spikey_richie spikey_richie is offline
Registered User
 
Join Date: Jun 2006
Location: Colton, CA
Posts: 26
Yes, in your class module do something like this

Code:
Public Sub Trade(param1 as string, param2 as string, param3 as string) As String
' we use sub instead of function as we're not looking for a return value
end sub
__________________
Geek it till it mHz
Reply With Quote
  #3 (permalink)  
Old 06-20-06, 21:16
mkggoh mkggoh is offline
Registered User
 
Join Date: Jun 2006
Posts: 103
Quote:
Originally Posted by spikey_richie
Yes, in your class module do something like this

Code:
Public Sub Trade(param1 as string, param2 as string, param3 as string) As String
' we use sub instead of function as we're not looking for a return value
end sub

but you are looking for a return value which is String. I bet this will cause an error
Reply With Quote
  #4 (permalink)  
Old 06-20-06, 21:23
spikey_richie spikey_richie is offline
Registered User
 
Join Date: Jun 2006
Location: Colton, CA
Posts: 26
Why not just say "remove the As String from the end as it'll cause an error"?
__________________
Geek it till it mHz
Reply With Quote
  #5 (permalink)  
Old 06-21-06, 09:49
MikeroSoft MikeroSoft is offline
Registered User
 
Join Date: Apr 2006
Posts: 47
actualy i am returning an object representing a stock exchange trade, so i will be seting a ref to the obj then using some of its functions & Properties


dim msft as new trade(Shares,price, commishion, purchdate)

msgbox "You now own " & msft.Shares & " Shares of Microsoft"
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On