Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic Examples => Topic started by: Frank Brübach on January 15, 2025, 04:46:28 PM

Title: Poke example
Post by: Frank Brübach on January 15, 2025, 04:46:28 PM
Hello..

I am looking for a simple poke example with o2. Peek I have found already , thanks
Title: Re: Poke example
Post by: Charles Pegge on January 15, 2025, 09:58:35 PM
string s="Hallo World"
byte *b
@b=strptr s
print b[2]  'peek  97  'a'
b[2]=101    'poke  101 'e'
print s
Title: Re: Poke example
Post by: Frank Brübach on January 15, 2025, 10:58:36 PM
Thank you but its Not very clear for me.. whats exactly  the difference between peek and poke?

uses console

' direct memory manipulation it is a statement provided
' by the language to write values to specific memory addresse

'---------------------- //
'
' that's code example is correct?
'
 DIM x AS BYTE, addr1 AS BYTE PTR
 'addr1 = STRPTR(x) 'VARPTR(x)
dim as byte addr1 at strptr(x)
 x = 5
 PRINT x '5
' POKE BYTE, addr1, 10 ' original
x=10
dim as byte addr1 at strptr(x)
 PRINT x '10
 '
wait
print "ok"

'---------------------- //
' ok below
string s="Hallo World"
byte *b
@b=strptr s

print b[2]  'peek  97  'a'
b[2]=101    'poke  101 'e'

print s '97
print b[2] '101
wait
' ends

Title: Re: Poke example
Post by: Charles Pegge on January 15, 2025, 11:49:59 PM
peek and poke are used in classic basic which does not support pointer variables. Peek is used for reading, and poke is used for writing at a defined memory location.