+ Reply to Thread
Results 1 to 7 of 7

problems with my class

  1. #1
    Registered User
    Join Date
    11-14-2004
    Location
    Georgia
    Posts
    57

    problems with my class

    i'm having a problem with one of my classes. i have 2 methods in my class(among others):

    Please Login or Register  to view this content.
    and a macro in a module:

    Please Login or Register  to view this content.
    i want to be able to have something like .IngredientName(1) = "Tomatoes" or .IngredientName(3) = "Sauce" where the "(see below)" comment is, but i'm not sure on how to structure my properties in order to do so. does anyone know how i can do this?

    thanks ahead of time,
    sven
    Brought to you by Pringles and his infinite genius. ~''~

    "Ctrl+Z is a beautiful thing."
    - Me.

  2. #2
    Registered User
    Join Date
    11-14-2004
    Location
    Georgia
    Posts
    57
    &bumps;

    i'm sorry, but this could land me my dream job.

  3. #3
    Bob Phillips
    Guest

    Re: problems with my class

    There seems to be a bit of missing info.

    I assume that Name and Size are other properties of the sandwich, and you
    are using a collection class, but you give no details, or where rgSandwich
    is.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "medicenpringles"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > i'm having a problem with one of my classes. i have 2 methods in my
    > class(among others):
    >
    >
    > Code:
    > --------------------
    > Property Let IngredientName(Index As Integer, sName As String)
    > If rgSandwich Is Nothing Then
    > IngredientName = ""
    > Else
    > rgSandwich.Offset(0, Index + 2).Value = sName
    > End If
    > End Property
    > Property Get IngredientName(Index As Integer) As String
    > If rgSandwich Is Nothing Then
    > UninitializedError
    > Else
    > IngredientName = rgSandwich.Offset(0, Index + 2).Value
    > End If
    > End Property
    > --------------------
    >
    >
    > and a macro in a module:
    >
    >
    > Code:
    > --------------------
    > Sub Testing()
    > Dim oSandwich As Sandwich
    > Dim oSandwiches As New Sandwiches
    >
    > Set oSandwich = oSandwiches.Add("Testing Sandwich")
    >
    > With oSandwich
    > .Name = "Testing Sandwich"
    > .Size = "Yeah"
    > ' (see below)
    > End With
    >
    > End Sub
    > --------------------
    >
    >
    > i want to be able to have something like .IngredientName(1) =
    > "Tomatoes" or .IngredientName(3) = "Sauce" where the "(see below)"
    > comment is, but i'm not sure on how to structure my properties in order
    > to do so. does anyone know how i can do this?
    >
    > thanks ahead of time,
    > sven
    >
    >
    > --
    > medicenpringles
    >
    >
    > ------------------------------------------------------------------------
    > medicenpringles's Profile:

    http://www.excelforum.com/member.php...o&userid=16458
    > View this thread: http://www.excelforum.com/showthread...hreadid=477929
    >




  4. #4
    Registered User
    Join Date
    11-14-2004
    Location
    Georgia
    Posts
    57
    well here's where rgSandwich is:

    Please Login or Register  to view this content.
    and here's name and size:

    Please Login or Register  to view this content.
    that help any?

  5. #5
    Registered User
    Join Date
    11-14-2004
    Location
    Georgia
    Posts
    57
    oh, SANDWICHES_WORKSHEET = "Sandwiches" , NAME_OFFSET = 0 AND SIZE_OFFSET = 1

  6. #6
    George Nicholson
    Guest

    Re: problems with my class

    Below is some code from a very similar situation. How much of this approach
    is appropriate for what you are trying to do is up to you.

    I used an array variable to store my Ingredient information within a
    Sandwich class (I also have a separate Ingredient class that contains
    PrepTime, Inventory counters, etc. for a Restaurant simulator). Since any
    given sandwich can have a variable number of ingredients, an Array seemed
    the only way to create a dynamic ingredient list for each sandwich. I was
    also storing # of Ingredient servings per sandwich, requiring a 2 dimension
    array. Whether you need/want that complexity is up to you.

    '****** Part of Piece/Sandwich class **********

    Private mintIngredientCount As Integer
    Private marrIngredients() As Variant 'IngrdID, Servings
    ....................

    Public Property Get IngredientCount() As Integer
    IngredientCount = mintIngredientCount
    End Property

    Private Property Let IngredientCount(ByVal iNewValue As Integer)
    ' Count is Incremented when Let_Ingredient is called
    mintIngredientCount = iNewValue
    If mintIngredientCount > 0 Then
    ReDim Preserve marrIngredients(1 To 2, 1 To mintIngredientCount)
    End If
    End Property

    Public Property Get Ingredients(iDim1 As Integer, idim2 As Integer) As
    Variant
    Ingredients = marrIngredients(iDim1, idim2)
    End Property

    Public Property Let Ingredients(iDim1 As Integer, idim2 As Integer, ByVal
    varNewValue As Variant)
    '(1,x) = IngredientID (i.e., Name, ID#)
    '(2,x) = IngredientQuant (i.e., # Servings)

    If idim2 > mintIngredientCount Then
    ' Expand array
    Me.IngredientCount = idim2
    End If

    marrIngredients(iDim1, idim2) = varNewValue
    End Property

    ******* end of class excerpt ******************

    With oSandwich
    .Name = "Testing Sandwich"
    .Size = "Yeah"
    .Ingredients(1,1) = "Tomatotes"
    ' ? Maybe .Ingredients(1,1) = rgSandwich.Offset(0, Index + 2).Value
    .Ingredients(2,1) = 2 '# of servings

    .Ingredients(1,2) = "Sauce"
    .Ingredients(2,2) = 1

    ' Example of how to access the stored information.
    For i = 1 to .IngredientCount
    ' List IngredientName, Servings
    Debug.Print .Ingredients(1,i); ", "; Ingredients(2,i)
    Next i
    End With


    HTH,
    --
    George Nicholson

    Remove 'Junk' from return address.


    "medicenpringles"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > i'm having a problem with one of my classes. i have 2 methods in my
    > class(among others):
    >
    >
    > Code:
    > --------------------
    > Property Let IngredientName(Index As Integer, sName As String)
    > If rgSandwich Is Nothing Then
    > IngredientName = ""
    > Else
    > rgSandwich.Offset(0, Index + 2).Value = sName
    > End If
    > End Property
    > Property Get IngredientName(Index As Integer) As String
    > If rgSandwich Is Nothing Then
    > UninitializedError
    > Else
    > IngredientName = rgSandwich.Offset(0, Index + 2).Value
    > End If
    > End Property
    > --------------------
    >
    >
    > and a macro in a module:
    >
    >
    > Code:
    > --------------------
    > Sub Testing()
    > Dim oSandwich As Sandwich
    > Dim oSandwiches As New Sandwiches
    >
    > Set oSandwich = oSandwiches.Add("Testing Sandwich")
    >
    > With oSandwich
    > .Name = "Testing Sandwich"
    > .Size = "Yeah"
    > ' (see below)
    > End With
    >
    > End Sub
    > --------------------
    >
    >
    > i want to be able to have something like .IngredientName(1) =
    > "Tomatoes" or .IngredientName(3) = "Sauce" where the "(see below)"
    > comment is, but i'm not sure on how to structure my properties in order
    > to do so. does anyone know how i can do this?
    >
    > thanks ahead of time,
    > sven
    >
    >
    > --
    > medicenpringles
    >
    >
    > ------------------------------------------------------------------------
    > medicenpringles's Profile:
    > http://www.excelforum.com/member.php...o&userid=16458
    > View this thread: http://www.excelforum.com/showthread...hreadid=477929
    >




  7. #7
    Bob Phillips
    Guest

    Re: problems with my class

    Not really, you have just introduced a lot more undefined code and you still
    haven't given us anything about the collection class which gets defined.

    Did you write this code, or borrow it from somewhere? Have you any idea what
    it is/supposed to do?

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "medicenpringles"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > well here's where rgSandwich is:
    >
    >
    > Code:
    > --------------------
    > Private Sub Class_Initialize()
    > If WorksheetExists(wbSandwichAnalysis, SANDWICHES_WORKSHEET) Then
    > Set wsSandwiches = wbSandwichAnalysis.Worksheets(SANDWICHES_WORKSHEET)
    > Else
    > Set wsSandwiches = Nothing
    > Err.Raise vbObjectError + 200, "Sandwich Class", "The worksheet named "

    & SANDWICHES_WORKSHEET & " could not be located."
    > End If
    > End Sub
    > --------------------
    >
    >
    > and here's name and size:
    >
    >
    > Code:
    > --------------------
    > Property Let Name(NameString As String)
    > If rgSandwich Is Nothing Then
    > Name = ""
    > Else
    > rgSandwich.Offset(0, NAME_OFFSET).Value = NameString
    > End If
    > End Property
    > Property Get Name() As String
    > If rgSandwich Is Nothing Then
    > UninitializedError
    > Else
    > Name = rgSandwich.Offset(0, NAME_OFFSET).Value
    > End If
    > End Property
    >
    > Property Let Size(SizeString As String)
    > If rgSandwich Is Nothing Then
    > Size = ""
    > Else
    > Select Case SizeString
    > Case "Small"
    > rgSandwich.Offset(0, SIZE_OFFSET).Value = SizeString
    > Case "Regular"
    > rgSandwich.Offset(0, SIZE_OFFSET).Value = SizeString
    > Case "Large"
    > rgSandwich.Offset(0, SIZE_OFFSET).Value = SizeString
    > Case "Flat Bread"
    > rgSandwich.Offset(0, SIZE_OFFSET).Value = SizeString
    > Case Else
    > Err.Raise vbObjectError + 514, "Sandwich Class", "Size not valid. " & _
    > "Either choose from valid sizes or create new size."
    > End Select
    > End If
    > End Property
    > Property Get Size() As String
    > If rgSandwich Is Nothing Then
    > UninitializedError
    > Else
    > Size = rgSandwich.Offset(0, SIZE_OFFSET)
    > End If
    > End Property
    > --------------------
    >
    >
    > that help any?
    >
    >
    > --
    > medicenpringles
    >
    >
    > ------------------------------------------------------------------------
    > medicenpringles's Profile:

    http://www.excelforum.com/member.php...o&userid=16458
    > View this thread: http://www.excelforum.com/showthread...hreadid=477929
    >




+ 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