Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15567

How To Cange Array Type ?

$
0
0
Hi ALL ~
How To Cange Array Type ?

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

Private Type VariantAPI
vt As Integer
wReserved1 As Integer
wReserved2 As Integer
wReserved3 As Integer
dwReserved1 As Long
dwReserved2 As Long
End Type

Private Sub Form_Load()
ReDim a1(11) As Double

Debug.Print vt_value(a1) ' = 24581

changeType a1

Debug.Print vt_value(a1) '---> Let a1() change to Single Type but not success ; vt still is 24581
End Sub

Private Function vt_value(ar)
Dim v As VariantAPI
Call CopyMemory(v, ByVal VarPtr(ar), LenB(v))
vt_value = v.vt
End Function
Private Function changeType(ar)
Dim v As VariantAPI

Debug.Print VarType(ar(1)), "VarType_1 = Double"
Call CopyMemory(v, ByVal VarPtr(ar), LenB(v))

v.vt = 24580 'to single type

Call CopyMemory(ar, ByVal VarPtr(v), LenB(v))

Debug.Print VarType(ar(1)), "VarType_2 = Single"


End Function

Viewing all articles
Browse latest Browse all 15567

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>