Home > Language Reference > System Functions > PokeInteger

PokeInteger

The PokeInteger function writes a value of type Integer or Unsigned to memory.

Syntax

ret = PokeInteger(<address>, <value>, <number_bytes>)

Parameters

<address>. unsigned variable only, address where to write. The unsigned variable must be declared at the beginning of the script using Dim function.

<value>, unsigned or integer, value to write in the memory.

<number_bytes>. integer, constant. It can be 1, 2 or 4 (1 byte to read, 2 bytes to read or 4 bytes to read).

Return value

ret, optional integer return value. If the value is successfully written, the return value is 0. If the function fails, the return value is a nonzero value (see System Functions Error Codes).

See also

PeekInteger
PokeString
PeekString$

Examples

dim Myvalue as unsigned
Myvalue=32500
ret=PokeInteger(MemPtr,myvalue,4)


'Script returning the ASCII codes for the string "Mystring"
'ASCII code for each letter of My string:
'77 121 32 115 116 114 105 110 103
'M y s t r i n g

dim pointer as unsigned
dim address as unsigned
'Write "My string" to memory
pointer=allocate(32)
ret=PokeString(pointer,"My string",1)
'Read the string as integers (ASCII codes)
i=0
repeat
address=pointer+i
var=PeekInteger(address,1)
mes$=mes$+"Byte "+str$(1+i)+" : "+str$(var)+"\n\"
i=i+1
until i=8

msgbox(mes$,64,"Memory")

'---------------------------------------------------------------
'Write integers in memory (ASCII codes)
pointer=allocate(32)
address=pointer
ret=PokeInteger(pointer,77,1)
pointer=pointer+1
ret=PokeInteger(pointer,121,1)
pointer=pointer+1
ret=PokeInteger(pointer,32,1)
pointer=pointer+1
ret=PokeInteger(pointer,115,1)
pointer=pointer+1
ret=PokeInteger(pointer,116,1)
pointer=pointer+1
ret=PokeInteger(pointer,114,1)
pointer=pointer+1
ret=PokeInteger(pointer,105,1)
pointer=pointer+1
ret=PokeInteger(pointer,110,1)
pointer=pointer+1
ret=PokeInteger(pointer,103,1)
'0 binary for end of string
pointer=pointer+1
ret=PokeInteger(pointer,0,1)

var$=PeekString$(address)
msgbox("String read : "+var$,64,"Memory ")