Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
problems with my class
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
problems with my class
&bumps; i'm sorry, but this could land me my dream job -- medicenpringle ----------------------------------------------------------------------- medicenpringles's Profile: http://www.excelforum.com/member.php...fo&userid=1645 View this thread: http://www.excelforum.com/showthread.php?threadid=47792 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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" <medicenpringles.1x7kej_1129824331.2715@excelfor um-nospam.com wrote in message news:medicenpringles.1x7kej_1129824331.2715@excelf orum-nospam.com... 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
Posted to microsoft.public.excel.programming
|
|||
|
|||
problems with my class
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 Su ------------------- 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 Propert ------------------- that help any -- medicenpringle ----------------------------------------------------------------------- medicenpringles's Profile: http://www.excelforum.com/member.php...fo&userid=1645 View this thread: http://www.excelforum.com/showthread.php?threadid=47792 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
problems with my class
oh, SANDWICHES_WORKSHEET = "Sandwiches" , NAME_OFFSET = 0 AN SIZE_OFFSET = -- medicenpringle ----------------------------------------------------------------------- medicenpringles's Profile: http://www.excelforum.com/member.php...fo&userid=1645 View this thread: http://www.excelforum.com/showthread.php?threadid=47792 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
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" <medicenpringles.1x7kej_1129824331.2715@excelfor um-nospam.com wrote in message news:medicenpringles.1x7kej_1129824331.2715@excelf orum-nospam.com... 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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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" <medicenpringles.1x7pyd_1129831520.7047@excelfor um-nospam.com wrote in message news:medicenpringles.1x7pyd_1129831520.7047@excelf orum-nospam.com... 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
aauugghhh...#div/o problems & various average formula problems | Excel Worksheet Functions | |||
Problems Setting properties of class module | Excel Programming | |||
Excell VBA - Class Modules problems | Excel Programming | |||
Collection Class problems | Excel Programming | |||
RaiseEvent from a class contained in a 2nd class collection? | Excel Programming |