advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
VARPTR, VARSEG Functions Details
  Summary  Details  Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
 VARPTR(variablename)
 VARSEG(variablename)
 
 Usage Notes
   ■ VARPTR and VARSEG return different values depending on the type of
     variable specified in variablename:
 
     Variable Type      Return Value (VARPTR)
     ═════════════      ════════════════════════════════════════════════════
     Numeric            Offset of the variable within its segment as an
                        unsigned integer
     String             Offset of string descriptor
     Not defined        Creates the variable and returns its address
 
     Variable Type      Return Value (VARSEG)
     ═════════════      ════════════════════════════════════════════════════
     Numeric            Segment address as an unsigned integer
     String             Segment address
     Not defined        Creates the variable and returns its address
 
   ■ Because many Visual Basic statements move variables in memory, use the
     values returned by VARPTR and VARSEG immediately after the functions
     are used.
 
   ■ VARPTR and VARSEG are often used with Absolute, BLOAD, BSAVE, Interrupt,
     PEEK, POKE, or when passing arrays to procedures written in other
     languages. See: Mixed-Language Programming Commands
 
   ■ When using VARPTR or VARSEG to get the address of an array, use the
     first element of the array as the argument:
 
         DIM A(150)
         .
         .
         .
         ArrAddress=VARPTR(A(1))
 
   ■ You can use VARPTR alone to get the address of a numeric variable stored
     in DGROUP. You must use both VARPTR and VARSEG to get the complete
     address of a numeric variable stored in far memory.
 
   ■ It is not meaningful to use VARSEG and VARPTR for strings. Since Visual
     Basic stores strings far, the format of the descriptor is different from
     previous versions of Basic. Use SSEG, SADD, and SSEGADD to return the
     address of string variables in Basic code. Use StringAddress to return
     the address of string variables from procedures written in other
     languages.  See: SADD Function     SSEG Function
                      SSEGADD Function  StringAddress Routine
 
   ■ You cannot use VARPTR to get the address of a file's buffer. Instead,
     use the FILEATTR function to get information about a file.
     See: FILEATTR Function
 
   ■ Programs written in Microsoft Basic version 3.0 or earlier that used
     VARPTR to access numeric arrays may no longer work. You must now use a
     combination of VARPTR and VARSEG. For example, the following Microsoft
     QuickBasic fragment no longer works correctly:
 
         DIM Cube(675)
         .
         .
         .
         BSAVE "graph.dat",VARPTR(Cube(1)),2700
 
     The fragment can be rewritten as follows to work in the current version
     of Visual Basic:
 
         DIM Cube(675)
         .
         .
         .                                     ' Change segment to segment
         DEF SEG=VARSEG(Cube(1))               ' containing Cube
         BSAVE "graph.dat",VARPTR(Cube(1)),2700
         DEF SEG                               ' Restore Visual Basic segment
 
   ■ The VARSEG function, combined with VARPTR, replaces the PTR86
     subprogram used in earlier versions of Basic.
 
   ■ Do not pass expanded memory arrays to non-Basic procedures. If you
     start Visual Basic (VBDOS.EXE) with the /Ea switch, any of these arrays
     may be stored in expanded memory:
     • Numeric arrays < 16K in size
     • Fixed-length string arrays < 16K in size
     • User-defined-type arrays < 16K in size
     See: VBDOS Command-Line Options
 
   ■ If you want to pass arrays to non-Basic procedures, first start Visual
     Basic (VBDOS.EXE) without the /Ea switch. Note: Without the /Ea switch,
     no arrays are stored in expanded memory.