Powerbasic Museum 2020-B

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Chris Chancellor on May 02, 2018, 07:10:34 AM

Title: Equivalent of PEEK$ statement in O2
Post by: Chris Chancellor on May 02, 2018, 07:10:34 AM
Hello Charles

In PB they have a PEEK$ statement, what is the equivalent in O2  ?

some people said that PEEK$ work could be done using the Mid()  statement
Title: Re: Equivalent of PEEK$ statement in O2
Post by: Patrice Terrier on May 02, 2018, 09:52:25 AM
Very easy to write your own, if you know how to work with pointers.
I have plainty of C++ code to emulate the PB string management, most of them are written for 64-bit UNICODE (Windows native).

They could be found in the Tools.h include file, that comes along in all my C++ projects.

The MoveMemory {RtlMoveMemory} API is also the lowest way to manipulate anything. And it works with any language.
Title: Re: Equivalent of PEEK$ statement in O2
Post by: Charles Pegge on May 02, 2018, 01:37:33 PM
Yes, copying with pointers is a fundamental ability. In o2, peek$ would require 2 steps

1 make a null string to receive the bytes
2 copy the bytes

copy dest, source, count

You can also copy to and from other variable types, such as ints, floats and UDTs. The compiler won't try to prevent you :)


'2018-05-02 T 12:11:03
'peek$
string s="0123456789"
string r=nuls 8
copy strptr(r),strptr(s)+1,8
print r
'
'peek int
string s="0123456789"
int v[2]
copy @v,strptr(s)+1,8
print hex(v[1]) ", " hex(v[2])
Title: Re: Equivalent of PEEK$ statement in O2
Post by: Chris Chancellor on May 02, 2018, 04:42:06 PM
Thanxx Charles and Patrice

as for the Peek$ , for  the string s="0123456789"

then
      string r=nuls 8

should have been
     string r=nuls 9 
     
bcos  the string length is 9
am i correct?


While for  the peek int , it should be
copy @v,strptr(s)+1,9

instead of
copy @v,strptr(s)+1,8


Title: Re: Equivalent of PEEK$ statement in O2
Post by: Charles Pegge on May 02, 2018, 07:05:23 PM
The demo was to peek at the middle 8 characters (ignoring 0 and 9).