Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Get the Data Type of a Property

Hi,
I'm building a microsoft excel program that reads through the
information in a text and creates a report off of it. I'm doing this
by building a class which I refer to as a CRecord as well as a
CRecords class which is just the collection of all the CRecords.
Obviously the all of the properties of the CRecord class aren't of the
same data type which has made me run into the problem that unless I
explicitly specify the data type when parsing the data and filling in
the properties of the CRecord I will sometimes get a type mismatch
error. What I would really like to do be able to somehow determine
the data type of the property that is being written to and have my
function automatically convert the data to that data type. Is that
possible? Here is my code:

Here is the Calling Procedu

....

Set gclsRecord = New CRecord

sSettlementDate = ImportData(6, 6)
sTradeDate = ImportData(3, 6)

With gclsRecord
.RecordType = clbRecordTypeData
.Record = CStr(lCurrentRow)

.TradeDate = DateSerial(Left(sTradeDate, 2),
Mid(sTradeDate, 3, 2), _
Right(sTradeDate, 2))

.SettlementDate = DateSerial(Left(sSettlementDate, 2),
_
Mid(sSettlementDate, 3, 2),
Right(sSettlementDate, 2))

.BuySellCode = ImportData(2, 1)
.MarketCode = ImportData(15, 1)
.BlotterCode = ImportData(16, 1)
.CancelCode = ImportData(17, 1)

.Branch = ImportData(18, 3)
.AccountNumber = ImportData(21, 6)
.CUSIP = ImportData(28, 9)
.TradeReferenceNumber = ImportData(37, 6)

.SecurityType = ImportData(43, 1)
.SecurityTypeModifier = ImportData(44, 1)
.SecurityTypeCalculation = ImportData(45, 1)

.RegisteredRep = ImportData(46, 3)
.AccountClassification = ImportData(59, 2)

.QuantitySign = ImportData(63, 1)
.Quantity = ChargeAdjustment(64, 14, ,
100000, , .QuantitySign)

.PrincipalSign = ImportData(97, 1)
.Principal = ImportData(98, 4)

.AlphaPriceDecimal = bIsDecimal(ImportData(87, 1))
.AlphaPriceDollar = GetAlphaPrice(ImportData(78, 9),
ImportData(88, 9))

End With
....

Here is the function that parses the data:

Public Function ImportData(lStartingPoint As Long, lLength As Long, _
Optional ByVal uDataType As clbDataType =
clbDataTypeString) As Variant

Dim sPropertyType As String

ImportData = Trim$(Mid(gclsMasterRecord.LineData, lStartingPoint,
lLength))

sPropertyType = gclsRecord.ActivePropertyType

If uDataType = clbDataTypeInteger Then
ImportData = CInt(Val(ImportData))

ElseIf uDataType = clbDataTypeDouble Then
ImportData = CDbl(Val(ImportData))

ElseIf uDataType = clbDataTypeLong Then
ImportData = CLng(Val(ImportData))

ElseIf uDataType = clbDataTypeString Then
ImportData = CStr(ImportData)

End If

End Function

I would really like to get rid of the uDataType variable in the
ImportData Function but doing so causes the type mismatch. Is it
possible to convert the ImportData to the proper data type without
having an argument telling ImportData what the data type is? It works
the way it is set up right now but I was just wondering if there is a
better way to do it without explicitly specifying the data type.
Thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Objects with .type property atpgroups Excel Programming 0 August 2nd 06 12:00 PM
Accessing Property of Custom Type Ronin Excel Programming 1 August 4th 05 09:58 PM
Return value of Property Get when using enumerated type jason Excel Programming 3 August 23rd 04 01:13 PM
Using Property Let with a Type as member of a Class Ken Dahlberg Excel Programming 5 December 21st 03 05:57 AM
How to find what object type is returned from Selection property ? Krzysztof Klimczak[_3_] Excel Programming 1 October 2nd 03 11:33 PM


All times are GMT +1. The time now is 04:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"