Why can't you use CopyMemory to copy a dimed variable in module using a pointer to the variable?
Here's My code
Form Code
When i Click The Button I get a illegal operation error.Code:Private Sub Command3_Click() Dim i As Integer Dim ThePointer As Long Dim TheLen As Integer Dim TheText As String Dim thetext1 As String ThePointer = test2(TheLen) CopyMemory TheText, ThePointer, TheLen For i = 1 To Len(TheText) Step 2 thetext1 = thetext1 & Mid(TheText, i, 1) Next Text4.Text = thetext1 End Sub here's the Module Code Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, ByVal Source As Any, ByVal Length As Long) Public Function test2(TheLen As Integer) As Long Dim MyStr as String MyStr = "Hope this works" TheLen = Len(MyStr) test2 = VarPtr(MyStr) End Function
If i Change the Dim MyStr as String to Private MyStr as String It works.
Why doesn't it work when i use the dim statement?




Reply With Quote