Just starting out? Need help? Post your questions and find answers here.
-
Lebostein
- Addict
- Posts: 807
- Joined: Fri Jun 11, 2004 7:07 am
Post
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))
-
Trond
- Always Here
- Posts: 7446
- Joined: Mon Sep 22, 2003 6:45 pm
- Location: Norway
Post
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)))
-
skywalk
- Addict
- Posts: 4003
- Joined: Wed Dec 23, 2009 10:14 pm
- Location: Boston, MA
Post
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)))
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
-
wilbert
- PureBasic Expert
- Posts: 3870
- Joined: Sun Aug 08, 2004 5:21 am
- Location: Netherlands
Post
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))
Windows (x64)
Raspberry Pi OS (Arm64)