working with types , Copy data of type inside other variable with different type
Hi
I would like working variables like below
Code:
Private Type AA
AA01 As String * 2
AA02 As String * 2
End Type
Private Type BB
BB01 As String * 4
End Type
Private Sub Form_Load()
Dim K As AA
Dim L As BB
K.AA01 = "11"
K.AA02 = "22"
'Here I want put the data of K inside L
'Is there some way to do it ?
End Sub
Re: working with types , Copy data of type inside other variable with different type
Code:
L.BB01 = K.AA01 & K.AA02
Debug.Print L.BB01
Re: working with types , Copy data of type inside other variable with different type
Thank you, But Is there some way to do put the put the data directly, no field by field
Like
L = K?
Re: working with types , Copy data of type inside other variable with different type
Look up the LSet statement.
Re: working with types , Copy data of type inside other variable with different type
Yes ofcourse, forgot all about the LSet statement!
Re: working with types , Copy data of type inside other variable with different type
My preference would be to write a function before using LSet.
Code:
Option Explicit
Private Type AA
AA01 As String * 2
AA02 As String * 2
End Type
Private Type BB
BB01 As String * 4
End Type
Private Sub Form_Load()
Dim K As AA
Dim L As BB
K.AA01 = "11"
K.AA02 = "22"
L = ToBB(K)
MsgBox L.BB01
End Sub
Private Function ToBB(A As AA) As BB
ToBB.BB01 = A.AA01 & A.AA02
End Function
Re: working with types , Copy data of type inside other variable with different type
If somebody is playing with UDTs for anything but API call "struct" stand-ins they are probably lost anyway.
Re: working with types , Copy data of type inside other variable with different type
Do you prefer classes above UDTs in all situations?
Re: working with types , Copy data of type inside other variable with different type
For me there is no one size fits all answer.