Page 1 of 1
Read a string from Structure with OfsetOf
Posted: Mon Jul 16, 2018 5:36 pm
by Lebostein
Reading Integers works, reading strings don't work:
Code: Select all
Structure xx
t1.a
t2.s
t3.i
t4.i
t5.s
EndStructure
xx.xx
xx\t1 = 5
xx\t2 = "text"
xx\t3 = 50
xx\t4 = 123456
xx\t5 = "other"
Debug PeekA(xx + OffsetOf(xx\t1))
Debug PeekS(xx + OffsetOf(xx\t2))
Debug PeekI(xx + OffsetOf(xx\t3))
Debug PeekI(xx + OffsetOf(xx\t4))
Debug PeekS(xx + OffsetOf(xx\t5))
Re: Read a string from Structure with OfsetOf
Posted: Mon Jul 16, 2018 5:51 pm
by Trond
PeekS() expects the address of the actual text, not the string variable.
Code: Select all
Structure xx
t1.a
t2.s
t3.i
t4.i
t5.s
EndStructure
xx.xx
xx\t1 = 5
xx\t2 = "text"
xx\t3 = 50
xx\t4 = 123456
xx\t5 = "other"
Debug PeekA(xx + OffsetOf(xx\t1))
Debug PeekS(PeekI(xx + OffsetOf(xx\t2)))
Debug PeekI(xx + OffsetOf(xx\t3))
Debug PeekI(xx + OffsetOf(xx\t4))
Debug PeekS(PeekI(xx + OffsetOf(xx\t5)))
Re: Read a string from Structure with OfsetOf
Posted: Mon Jul 16, 2018 5:53 pm
by skywalk
The address of PB strings are stored in the Structure. If you want strings directly in the Structure, then use a byte or char array.
Code: Select all
Structure xx
t1.a
t2.s
t3.i
t4.i
t5.s
EndStructure
xx.xx
xx\t1 = 5
xx\t2 = "text"
xx\t3 = 50
xx\t4 = 123456
xx\t5 = "other"
Debug PeekA(xx + OffsetOf(xx\t1))
Debug PeekS(PeekI(xx + OffsetOf(xx\t2)))
Debug PeekI(xx + OffsetOf(xx\t3))
Debug PeekI(xx + OffsetOf(xx\t4))
Debug PeekS(PeekI(xx + OffsetOf(xx\t5)))
Re: Read a string from Structure with OfsetOf
Posted: Mon Jul 16, 2018 6:32 pm
by wilbert
skywalk wrote:If you want strings directly in the Structure, then use a byte or char array.
or a fixed string.
Code: Select all
Structure xx
t1.a
t2.s{20}
t3.i
t4.i
t5.s{20}
EndStructure
xx.xx
xx\t1 = 5
xx\t2 = "text"
xx\t3 = 50
xx\t4 = 123456
xx\t5 = "other"
Debug PeekA(xx + OffsetOf(xx\t1))
Debug PeekS(xx + OffsetOf(xx\t2))
Debug PeekI(xx + OffsetOf(xx\t3))
Debug PeekI(xx + OffsetOf(xx\t4))
Debug PeekS(xx + OffsetOf(xx\t5))
Re: Read a string from Structure with OfsetOf
Posted: Mon Jul 16, 2018 7:22 pm
by Lebostein
THANKS!