Results 1 to 4 of 4

Thread: Testing DataTypes

  1. #1

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Question Testing DataTypes

    Is there a function for testing the actual datatype of an object? I have an application that should run a certain procedure whenever an Outlook.MailItem is opened, by passing the Inspector.CurrentItem into the procedure as a parameter. However, if the user actually opened a read-receipt, this causes an error because the Inspector.CurrentItem is now an Outlook.ReportItem instead.

    Is there a way of saying something like:
    VB Code:
    1. If DataType(Inspector.CurrentItem) = Outlook.MailItem Then
    TIA...
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well there's the TypeName() function.
    But I dont know if it'll work with these sorts of types.

    If it doesnt, then you could infer what sort of data type it is.
    Something like :

    VB Code:
    1. Private Function GetDataType(myObj As Variant) As String
    2.     'check the different properties of the control and infer what it is
    3. End Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819
    Jamie,

    Didn't know about the TypeName function, but it works a treat. Thanks.
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Or you could try passing the variable to a set of functions, each one of which is expecting a specific data type.

    You catch the errors, and check which one didnt throw an error.

    Then you know what type it is.
    I think this is how I would do it.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width