View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
brad brad is offline
external usenet poster
 
Posts: 32
Default textboxes and datatypes

Do you want to avoid using datatype conversion functions?
CStr, Cdate, CInt, etc.

-Brad
-----Original Message-----
I've used a class module to define my object with various

properties and methods which interact with each other. I
then populate a collection (database) with my objects
(records). I have a userform for adding a new record, or
calling up an existing record. The fields (textboxes) on
the form correspond to the properties of my class module.

In the class module I have written all the code for the

interaction between the properties, and I want exactly the
same rules to apply to the userform. I've been trying to
accomplish this by using the same code, but my problem is
that textboxes hold text, and the various properties of my
class module can hold dates, currency, etc. There's
no "type" property for my textboxes.

Can I tell VBA what type of data is stored in each of the

textboxes in my form so that my calculations will work?
and / or
Is there another way around this that I'm missing?

Thanks very much for any help
Rob


'I populate my collection
Set DataBase = New Collection
For i = 2 To LastRow(3, DataSheet.Name,

ThisWorkbook.Name)
Set Record = New MyClass
Record.OrderNumber = DataSheet.Cells(i, 3)
DataBase.Add Record
Next


'when I change the OrderNumberTextbox on my form:
Private Sub OrderNumber_Change()
Set ThisOrder = New MyClass
With ThisOrder
.OrderNumber = OrderNumber
'If the order number already exists in my collection

the other properties are set
'...then I fill in the textboxes
OrderDate = .OrderDate
DeliveryDate = .DeliveryDate
Supplier = .Supplier
Description = .Description
OrderValue = .OrderValue
InvoiceValue = .InvoiceValue
'when i try to do a calculation, eg.
if OrderDate = DeliveryDate then CalculationTextBox =

OrderValue - InvoiceValue
'everything goes wrong because it thinks everything is

text
End With


.