Results 1 to 7 of 7

Thread: Determine Variant Data Type (wrt Hard Data Types) [Resolved]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    159

    Determine Variant Data Type (wrt Hard Data Types) [Resolved]

    Hi,

    I am using a variant parameter in a function to simplify my UI for a control. When that funciton is called, the variant parameter will either be a string or a long. I need to determine which has been passed.

    (One problem is that a string argument can begin with a number, so that rules out using the VAL function.)
    (Since the argument is not an object, I cannot use the IS operator.)

    How can I determine the data type of the variant within the function?


    Cheers,
    Nap.
    Last edited by Napoleon; Apr 8th, 2006 at 02:55 AM.

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Determine Variant Data Type (wrt Hard Data Types)

    Would this work?

    VB Code:
    1. Private Sub Form_Load()
    2. GetType "1231ABC"
    3. End Sub
    4. Private Sub GetType(StrVal As Variant)
    5. If IsNumeric(StrVal) Then
    6.     MsgBox "Is a number"
    7. Else
    8.     MsgBox "Is a string"
    9. End If
    10. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    159

    Re: Determine Variant Data Type (wrt Hard Data Types)

    Thanks for that.

    Nap

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Determine Variant Data Type (wrt Hard Data Types) [Resolved]

    Or use TypeName()

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    159

    Re: Determine Variant Data Type (wrt Hard Data Types) [Resolved]

    Penagate,

    I will use that one.
    It covers all the core variable types that VB has.

    Thanks,
    Nap

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Determine Variant Data Type (wrt Hard Data Types) [Resolved]

    I see that you took the trouble to edit your subject to add Resolved. Thanks for doing that but the easy way is to pull down the Thread Tools menu and click the Mark Thread Resolved button.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    159

    Re: Determine Variant Data Type (wrt Hard Data Types) [Resolved]

    Thanks for the info. Didn't know it was there.

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