Q(uick)BASIC Function: SSEG

Quick View

SSEG

A function that returns the segment address for a string

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • SSEG(stringvariable$)
Description/Parameter(s)
stringvariable$ The string variable for which you want to find the segment address. It can be a simple string variable or a single element of a string array. You cannot use fixed-length string arguments.
SSEG returns the segment address of the argument (or 0 if the argument is a null string).

This function is typically used in mixed-language programming to obtain far addresses before passing far strings to procedures written in other languages.

Usage Notes

  • SSEG usually is used with far strings but can also be used with strings stored in DGROUP (in which case it returns DGROUP's address).
  • The offset of a string can be found by using the SADD function; both the segment and offset can be found with the SSEGADD function.

Programming With OS/2 Protected Mode

  • The SSEG function returns the selector of the specified string variable.
Example

This example creates a string and then calculates its offset and segment using the SADD and SSEG functions. The information is then passed to a BASIC SUB procedure which mimics the performance of a non-BASIC print routine.

DEFINT A-Z 'Create the string. Text$ = ".... a few well-chosen words" 'Calculate the offset, segment and length of the string. Offset = SADD(Text$) Segment = SSEG(Text$) Length = LEN(Text$) 'Pass these arguments to the print routine. CALL printit(Segment, Offset, Length) END SUB printit (Segment, Offset, Length) CLS 'Set the segment for PEEKing. DEF SEG = Segment FOR i = 0 TO Length - 1 'Get each character from memory, convert to ASCII, and display. PRINT CHR$(PEEK(i + Offset)); NEXT i END SUB