$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) '/*------------------------------------------------------------------*/ $CODE SEG "MLIB1" '/*------------------------------------------------------------------*/ ' CENTER(STRING,LENGTH,PAD) ' Returns a string of length LENGTH, with STRING centered in it, ' with PAD characters added as necessary to make up the required ' length. If STRING is longer than LENGTH, it will be truncated ' at both ends to fit. If an odd number of characters are ' truncated or added, the right hand end loses or gains one more ' character than the left hand end. ' EXAMPLES: PRINT CENTER("abc",7," ") ' abc ' ' PRINT CENTER("abc",8,"-") '--abc---' ' PRINT CENTER("The Blue Sky",8," ") 'e blue s' ' PRINT CENTER("The Blue Sky",7," ") 'e blue ' '/*------------------------------------------------------------------*/ FUNCTION CENTER(BYVAL X AS STRING, BYVAL L AS INTEGER, BYVAL PAD AS STRING) PUBLIC AS STRING LX = LEN(X) IF LX > L THEN LD = LX - L LL = FIX(LD/2) LR = LD - LL XRET$ = MID$(X,LL+1,LX-LR-LL) ELSE XRET$ = STRING$(L,PAD) LS = FIX((L-LX)/2) + 1 MID$(XRET$,LS,LX) = X END IF FUNCTION = XRET$ END FUNCTION '/*------------------------------------------------------------------*/ ' CLS ' PRINT "'"CENTER("SSAN",9," ")"'";" ' abc ' " ' PRINT CENTER("abc",8,"-");" '--abc---' " ' PRINT CENTER("The Blue Sky",8," ");" 'e blue s' " ' PRINT CENTER("The Blue Sky",7," ");" 'e blue ' " ' PRINT CENTER("The Title",80,"*");" " ' INPUT Z