View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default User-defined Type Issue

Your code was fine - all I had to do was set some value in tbxQuantity

making sure
OPTION EXPLICIT
is at the top of each module would have highlighted this

"Ryan H" wrote:

I reed the with statement help and it said it could be used with any
user-defined type. Do you know why it wouldn't work in my application?


--
Cheers,
Ryan


"Patrick Molloy" wrote:

to use totals type you'd need to be absolute

ie

some_material = total.material

an alternative would be to open a new CLASS MODULE, name it cTotals and give
it the variables that you gave to the type.

now you'd SET total = New cTotals

as total is an object of class cTotals, you can use the WITH method as you
showed.












"Ryan H" wrote:

I have a UDF below that is located in a Standard Module.

Type Totals
COGS As Double
Material As Double
Labor As Double
UnitPrice As Currency
QuotePrice As Currency
End Type

I declared a Public Variable in another Standard Module like this.

Public Total As Totals

For some reason when I use Total with the With...End With Statement in the
code below VBA is throwing an exception stating "With object must be
user-defined type, variant or object". Anybody know why?

Sub Test()

With Total

' determines labor effiency % and COGS %
Select Case Val(tbxQuantity)
Case Is = 1
.COGS = 1.1
Case Is = 2
.COGS = 1.08
Case Is = 3
.COGS = 1.05
End Select

.Material = 300
.Labor = 1000
End With

End Sub

--
Cheers,
Ryan