Results 1 to 7 of 7

Thread: Class attributes (NewB QUESTION)(RESOLVED)

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2003
    Posts
    38

    Class attributes (NewB QUESTION)(RESOLVED)

    Currently i have a class called clsLoanPolicy which is as below:
    VB Code:
    1. Option Explicit
    2.  
    3. Private cMaxLoanLimit As Currency
    4. Private iOverdueCharges As Integer
    5.  
    6. Public Property Get MaxLoanLimit() As Variant
    7.     MaxLoanLimit = cMaxLoanLimit
    8. End Property
    9.  
    10. Public Property Let MaxLoanLimit(ByVal vNewValue As Variant)
    11.     cMaxLoanLimit = vNewValue
    12. End Property
    13.  
    14. Public Property Get OverdueCharges() As Variant
    15.     OverdueCharges = iOverdueCharges
    16. End Property
    17.  
    18. Public Property Let OverdueCharges(ByVal vNewValue As Variant)
    19.     iOverdueCharges = vNewValue
    20. End Property

    What must i add in the class that will set the cMaxLoanLimit and iOverdueCharges as 200 and 2 respectively.

    Then when users create objects of the class, they can use the getters to get the attributes value which should show 200 and 2
    and also to use setters to set new attributes values.
    In other words, making this class a sort of file to permanently store the attributes.
    Last edited by yyayl; Apr 15th, 2003 at 07:17 AM.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You can use the Class_Initialize event to set initial values to cMaxLoanLimit and iOverdueCharges.
    VB Code:
    1. Private Sub Class_Initialize()
    2.     cMaxLoanLimit = 200
    3.     iOverdueCharges = 2
    4. End Sub
    May I ask why your property procedures returns and accept Variants when MaxLoanLimit should be in Currency and OverdueCharges in Integer according to your private variables?

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2003
    Posts
    38
    Thx for the ans Joacim
    May I ask why your property procedures returns and accept Variants when MaxLoanLimit should be in Currency and OverdueCharges in Integer according to your private variables?
    ermm.... no idea.
    Isnt variant the default vb data type and holds any type of data?

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    A variant can be ANY data type and due to this is scoffs a lot more memory. Since your properties are for a specific datatype, ie currency, then the property should also be curreny...

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2003
    Posts
    38
    Originally posted by Wokawidget
    A variant can be ANY data type and due to this is scoffs a lot more memory. Since your properties are for a specific datatype, ie currency, then the property should also be curreny...

    ahhhhhhhhh....... now these are the stuffs they dont say in the lecture notes.
    then again i shouldnt expect much when the lecture notes are never more than 10 pages for a single topic

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    not to mention the fact that you could pass text to it rather than numbers. if you use the proper data type then VB will force the coder to pass valid data to the class

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2003
    Posts
    38
    Originally posted by si_the_geek
    not to mention the fact that you could pass text to it rather than numbers. if you use the proper data type then VB will force the coder to pass valid data to the class

    ahhh......
    The NewB learns something new again !
    Then again, maybe not......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width