$CPU 8086 ' make compatible with XT systems $LIB ALL OFF ' turn off all PowerBASIC libraries $ERROR ALL OFF ' turn off all PowerBASIC error checking $OPTIMIZE SIZE ' optimize for smaller code $COMPILE UNIT ' compile to a UNIT (.PBU) '$COMPILE EXE ' compile to a UNIT (.PBU) DEFINT A-Z ' Required for all numeric functions, forces PB to not ' include floating point in UNIT (makes it smaller) '/*------------------------------------------------------------------*/ ' DECLARE FUNCTION ArrayInfo(BYVAL Code AS INTEGER, ArrayDescriptor AS ANY) AS LONG $CODE SEG "MLIB5" '/*------------------------------------------------------------------*/ FUNCTION LASTELE(temp AS STRING) PUBLIC AS INTEGER DIM RL AS INTEGER ! push DS ; save DS for PowerBASIC ! mov CX, -1 ; search 64k of string handles ! lds SI, temp ; point ES:DI to first string handle TestLoop: ! lodsw ; load handle into AX ! or AX, AX ; check to see if it's zero ! loopnz TestLoop ; loop if not zero ! jnz Done ; not zero, exit ! not CX ; convert to positive value '/* ! mov FUNCTION, CX ; return function result ! mov RL, CX ; return function result Done: ! pop DS ; restore DS for PowerBASIC RL = RL - 1 FUNCTION = RL END FUNCTION '/*-------------------------------------------------------------------- ' CLS ' DIM x AS INTEGER ' DIM A$(1:100) ' ' FOR x = 1 TO 30 ' A$(x) = STR$(x) ' NEXT x ' PRINT LASTELE(A$(1)) 'start search with first element ' X = ArrayInfo(1,A$()) ' PRINT X ' INPUT Z