'=========================================================================== ' Subject: DIFFERENCE BETWEEN SADD/VARPTR Date: 07-09-96 (21:36) ' Author: Bob Perkins Code: QB, QBasic, PDS ' Origin: FidoNet QUIK_BAS Echo Packet: MEMORY.ABC '=========================================================================== ' > Does anyone know if there is a difference between ' > SADD and VARPTR? If ' They are both provided to find the offset (address) of a variable. VARSEG 'is used to get the segment. Though they may appear similar in function, they 'do have differences. SADD is not to be used with TYPEs or fixed-length 'strings. VARPTR is used with those. VARPTR can be used with simple string 'variables, but it does not return the offset of the string but rather the 'offset of the string descriptor. From that you can determine the address and 'length of the string. Note: Be careful playing around with poking directly 'into strings in memory. You could find yourself facing a "String Space 'Corrupt" error message if you inadvertantly change the length. Following is 'some rambling code examples to show how to use VARPTR, VARSEG, and SADD. Hope 'it helps you to understand better. CLS s$ = "test" segment% = VARSEG(s$) PRINT "Segment of s$ returned by VARSEG="; segment% PRINT ' offset% = SADD(s$) PRINT "Offset of s$ as returned by SADD="; offset% DEF SEG = segment% PRINT "Contents of s$ = "; FOR x% = 0 TO LEN(s$) - 1 PRINT CHR$(PEEK(offset% + x%)); NEXT x% PRINT : PRINT ' descroffset% = VARPTR(s$) strlength% = PEEK(descroffset%) + PEEK(descroffset% + 1) * 256 stroffset% = PEEK(descroffset% + 2) + PEEK(descroffset% + 3) * 256 PRINT "Offset of s$'s string descriptor returned by VARPTR="; descroffset% PRINT "Offset of s$ from string descriptor="; stroffset% PRINT "Length of s$ from string descriptor="; strlength% ' PRINT DIM fixed AS STRING * 10 fixed = "0123456789" offset% = VARPTR(fixed) segment% = VARSEG(fixed) PRINT "Offset of fixed length variable from VARSEG="; segment% PRINT "Offset of fixed length variable from VARPTR="; offset% PRINT "Contents of fixed length string="; DEF SEG = segment% FOR x% = 0 TO 9 PRINT CHR$(PEEK(offset% + x%)); NEXT x% PRINT