mrhicks
April 6th, 2001, 08:36 PM
Hello all,
I would like to know how would I pass a private UDT delcared within form1 to a public member of another form? I have been playing around with the CopyMemory and VarPtr funtions, but I can only get it to work paritially. Below is a part of the code..
Globals.Bas
option Explicit
Const CAPITEXTLEN = 25
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst as Any, _
pSrc as Any, _
byval ByteLen as Long)
public Type MY_STRUCTURE
Param1 as string * CAPITEXTLEN
Param2 as string * CAPITEXTLEN
Param3 as string * CAPITEXTLEN
Param4 as Long
Param5 as Long
End Type
frmForm1.frm
option Explicit
private MyVariable as MY_STRUCTURE
private Sub cmdPassData_Click()
Dim ptrMyVariable as Long
With MyVariable
.Param1 = "String1"
.Param2 = "String2"
.Param3 = "String3"
.Param4 = 12
.Param5 = 18
End With
' CopyMemory ptrMyVariable, MyVariable, 4
frmForm2.mEntryPoint VarPtr(MyVariable)
End Sub
frmForm2.frm
option Explicit
private MyVariabl2 as MY_STRUCTURE
public Sub mEntryPoint(byref ptrPassedVariable as Long)
CopyMemory MyVariabl2, byval ptrPassedVariable, 4
With MyVariabl2
Text1.Text = .Param1
Text2.Text = .Param2
Text3.Text = .Param3
Text4.Text = .Param4
Text5.Text = .Param5
End With
me.Show vbModal
End Sub
I am not sure what I am doing wrong... I think I have the right idea, but I may be going about it the hard way. Any thoughts? Thanks
Mark H.
I would like to know how would I pass a private UDT delcared within form1 to a public member of another form? I have been playing around with the CopyMemory and VarPtr funtions, but I can only get it to work paritially. Below is a part of the code..
Globals.Bas
option Explicit
Const CAPITEXTLEN = 25
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst as Any, _
pSrc as Any, _
byval ByteLen as Long)
public Type MY_STRUCTURE
Param1 as string * CAPITEXTLEN
Param2 as string * CAPITEXTLEN
Param3 as string * CAPITEXTLEN
Param4 as Long
Param5 as Long
End Type
frmForm1.frm
option Explicit
private MyVariable as MY_STRUCTURE
private Sub cmdPassData_Click()
Dim ptrMyVariable as Long
With MyVariable
.Param1 = "String1"
.Param2 = "String2"
.Param3 = "String3"
.Param4 = 12
.Param5 = 18
End With
' CopyMemory ptrMyVariable, MyVariable, 4
frmForm2.mEntryPoint VarPtr(MyVariable)
End Sub
frmForm2.frm
option Explicit
private MyVariabl2 as MY_STRUCTURE
public Sub mEntryPoint(byref ptrPassedVariable as Long)
CopyMemory MyVariabl2, byval ptrPassedVariable, 4
With MyVariabl2
Text1.Text = .Param1
Text2.Text = .Param2
Text3.Text = .Param3
Text4.Text = .Param4
Text5.Text = .Param5
End With
me.Show vbModal
End Sub
I am not sure what I am doing wrong... I think I have the right idea, but I may be going about it the hard way. Any thoughts? Thanks
Mark H.