Results 1 to 7 of 7

Thread: Pointers

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    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
    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
    When i Click The Button I get a illegal operation error.
    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?
    Last edited by Bjwbell; Jan 28th, 2001 at 09:27 PM.
    VB-World addict!

    All spelling errors are undocumented words!
    http://www.bells.f2s.com

Posting Permissions

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



Click Here to Expand Forum to Full Width