dcsimg
Results 1 to 4 of 4

Thread: How to convert Variant to Type

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    13

    How to convert Variant to Type

    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

    Private Type vt ' what is Correct type definition
    vType As Integer
    p1 As Long
    p2 As Long
    p3 As Long
    p4 As Long
    p5 As Long
    p6 As Long
    p7 As Long
    p8 As Long
    p9 As Long
    pa As Long
    End Type

    Private Sub Form_Load()

    ReDim a(1 To 1000) As Long

    dim b as Variant

    b = a

    Dim vt As vt

    CopyMemory vt, VarPtr(b), Len(vt)

    End Sub

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to convert Variant to Type

    What exactly are you trying to do ?

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    13

    Re: How to convert Variant to Type


  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to convert Variant to Type

    Quote Originally Posted by quickcccc View Post
    what is Correct type definition

    Code:
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
       
    vt is just a name you decide. Your array contains 1 Integer and 9 Long variables. What you
    want to name it is entirely up to you. 
    
    Private Type vt    ' what is Correct type definition
       vType As Integer
       p1 As Long
       p2 As Long
       p3 As Long
       p4 As Long
       p5 As Long
       p6 As Long
       p7 As Long
       p8 As Long
       p9 As Long
       pa As Long
    End Type
    
    Private Sub Form_Load()
    
     Before you can ReDim a you must first Dim a like this: Dim a() As type_name where type_name is probably vt in your case
     
     ReDim a(1 To 1000) As Long
     
      dim b as Variant
     
      b = a '<--------- ------------ No
    
      Like this:
     
      b = a(n) where n is a number 1 to 1000 
    
    
      Dim vt As vt '<------------------------ Can not Dim object name same as Type name
     
      CopyMemory vt, VarPtr(b), Len(vt)
    
    End Sub
    Other that that I have no idea what you want to acompolish. You dont convert a variant to a type but you can have a Type of variants.

    Code:
    Private Type vt    ' what is Correct type definition
       vType As Variant
       p1  As Variant
       p2  As Variant
       p3  As Variant
       p4  As Variant
       p5  As Variant
       p6  As Variant
       p7  As Variant
       p8  As Variant
       p9  As Variant
       pa  As Variant
    End Type
    Last edited by jmsrickland; Sep 4th, 2012 at 06:55 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width