Navigation:  ThinBASIC Modules > Core (thinBasic Core Engine) > Memory handling and pointers >

PEEK$

Previous pageReturn to chapter overviewNext page

 

Description

 

Return sequence of bytes at a specified memory location.

 

Syntax

 

s = PEEK$(address, count)

s = PEEK$(ASCIIZ, address [, count])

s = PEEK$(STRING, address)

 

Returns

 

String

 

Parameters

 

Name

Type

Optional

Meaning

ASCIIZ

Command

Yes

Optional parameter indicating that address is to be considered a pointer to a NULL terminated string.

If ASCIIZ is specified, PEEK$ reads successive characters from an ASCIIZ buffer of the specified size, until a terminating $NUL (CHR$(0)) byte is found.  Since ASCIIZ strings must contain a terminating $NUL, the maximum length of the returned string is 1 character less than the specified size.

STRING

Command

Yes

If STRING is specified, address is interpreted as a 32 bit placeholder for a dynamic string. This form allow handling dynamic strings inside UDT or using whatever 32 bit number as dynamic string.

Address

Numeric

No

A valid 32-bit memory address specifying the location in memory where data retrieval should begin

Count

Numeric

No

A numeric expression that specifies the number of consecutive bytes to be read from memory starting at address.

In case of ASCIIZ, if count is omitted, bytes till the next $NUL char will be automatically determined.

 

Remarks

 

Restrictions

 

See also

 

STRPTR, VARPTR, POKE$, POKE, PEEK$, PEEK

 

Examples

 

'---Example using STRING for to handle dynamic strings inside UDT structures.

Type MyType

  Name   As Long

  ID     As Long

  Notes  As Long

End Type

 

Dim MyUSer As MyType

 

POKEStringVARPTR(MyUSer.Name) , "MyName"

POKEStringVARPTR(MyUSer.ID)   , "MyID"

POKEStringVARPTR(MyUSer.Notes), "Whatever string or data or binary sequence are allowed"

 

MSGBOX 0, _

          "[" & PEEK$(StringVARPTR(MyUser.Name) ) & "]" & $crlf & _

          "[" & PEEK$(StringVARPTR(MyUser.ID)   ) & "]" & $crlf & _

          "[" & PEEK$(StringVARPTR(MyUser.Notes)) & "]" & $crlf