+ Reply to Thread
Results 1 to 3 of 3

A problem with creating own class in EXCEL 2003

Hybrid View

  1. #1
    Registered User
    Join Date
    12-10-2009
    Location
    Saratov
    MS-Off Ver
    Excel 2003
    Posts
    7

    A problem with creating own class in EXCEL 2003

    I trying to create my own class in class model in Excel. It is a code :
    Private cshort_name As String
    Private crevenue As Double
    Private crevard As Double
    Private cmarja As Double
    Private ctrading As Integer
    Private cshort As Integer
    Private ccode As String
    Private cweigth As Double
    Private cdiver As Integer
    Private cprice As Double
    Private cprice_1 As Double
    Private cprice_2 As Double
    Private crest As Integer
    Private cmax_pos As Double
    Private crest_limit As Double
    
    Public Property Get short_name() As String
        short_name = cshort_name
    End Property
    Public Property Let cshort_name(Value As String)
        cshort_name = Value
    End Property
    
    Public Property Get revenue() As Double
        revenue = crevenue
    End Property
    Public Property Let revenue(Value As Double)
         crevenue = revenue
    End Property
    
    Public Property Get revard() As Double
        revard = crevard
    End Property
    Public Property Let crevard(Value As Double)
      If Value >= 0 Or Value <= 1 Then
        crevard = Value
        Else
        messagebox ("Польза может быть только больше 0 и меньше 1")
        crevard = 0
        End If
    End Property
    
    Public Property Get marja() As Double
        marja = cmarja
    End Property
    Public Property Let cmarja(Value As Double)
      If Value >= 0 Or Value <= 1 Then
        cmarja = Value
        Else
        messagebox ("Маржа может быть только больше 0 и меньше 1")
        cmarja = 0
        End If
    End Property
    
    Public Property Get trading() As Integer
        trading = ctrading
    End Property
    Public Property Let ctrading(Value As Integer)
      If Value = 0 Or Value = 1 Then
        ctrading = Value
        Else
        messagebox ("Флаг может принимать либо значение 0 либо 1")
        ctrading = 0
        End If
    End Property
    
    Public Property Get short() As Integer
        short = cshort
    End Property
    Public Property Let cshort(Value As Integer)
      If Value = 0 Or Value = 1 Then
        cshort = Value
        Else
        messagebox ("Флаг может принимать либо значение 0 либо 1")
        cshort = 0
        End If
    End Property
    
    Public Property Get code() As String
        code = ccode
    End Property
    Public Property Let ccode(Value As String)
        ccode = Value
    End Property
    
    Public Property Get weigth() As Double
        weigth = cweigth
    End Property
    Public Property Let cweigth(Value As Double)
    
    If Value < 1 Then
    messagebox ("Диверсификация не может быть меньше 1")
    cweigth = 1
    Else
    cweigth = Value
    End If
    
    End Property
    
    Public Property Get price() As Double
    price = cprice
    End Property
    Public Property Let cprice(Value As Double)
    cprice = Value
    End Property
    
    Public Property Get price_1() As Double
        price_1 = cprice_1
    End Property
    Public Property Let cprice_1(Value As Double)
    cprice_1 = Value
    End Property
    
    Public Property Get price_2() As Double
        price_ = cprice_
    End Property
    Public Property Let cprice_2(Value As Double)
    cprice_2 = Value
    End Property
    And after i trying to create an instance of this class using button

    Private Sub CommandButton1_Click()

    Dim stock As Class1
    Set stock = New Class1

    End Sub
    But then i press the button this message has occured :
    http://s54.radikal.ru/i146/0912/fa/25a9b043faff.jpg

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: A problem with creating own class in EXCEL 2003

    The error "Ambiguous name detected: cshort_name"
    is caused by having a Let property,

    Public Property Let cshort_name(Value As String)
        cshort_name = Value
    End Property
    with the same name as the private variable used to store it's value.

    Give the private variable a new name.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    12-10-2009
    Location
    Saratov
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: A problem with creating own class in EXCEL 2003

    Thanks! It is work!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1