I have been learning about memory. Slowly it is coming together but I am still have problems. I made a simple app that stores a value in a variable. A loop then starts and in that loop I use Bool to switch back and forth adding 1 to variable and then changing it back by subtract 1. I made it continue to switch so I could find its location in memory. I found it with no problems.

Its location:

Hex 0014E618

Dec 1369624

Just so you can check me if needed here is simple app:

VB Code:
  1. Dim trigger As Boolean
  2. Dim looper As Boolean
  3. Dim counter As Integer
  4.  
  5.  
  6. Private Sub Command1_Click()
  7. Wait 4
  8. trigger = False
  9. looper = False
  10. counter = 9022  'store value
  11.   Do While trigger = False
  12.     If looper = False Then
  13.      counter = counter + 1  ' now is 9023
  14.      Me.Print counter   ' show me
  15.      looper = True
  16.     Else
  17.      counter = counter - 1   ' next value back to original
  18.      Me.Print counter  ' show me
  19.      looper = False
  20.     End If
  21. Wait 5
  22. Form1.Cls
  23.   Loop
  24. End Sub


Now I know the location of this variable in memory. I try to use CopyMemory to change the value like so...

VB Code:
  1. Option Explicit
  2.  
  3. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, source As Any, ByVal bytes As Long)
  4. Dim intValue As Long
  5.  
  6. Private Sub Command1_Click()
  7.  
  8.    Wait 4
  9.    Dim address As Long
  10.    address = 1369624   'decimal form
  11.    intValue = 4444  ' new value
  12.    CopyMemory address, intValue, 4
  13.  
  14. End Sub


I have tried..

VB Code:
  1. CopyMemory byval address, intValue, 4

but all I get is a crash.


Any suggestions would be great! TY^^