home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1995 September / Image.iso / visualob / install / samples / employee / udflib.pr_ / udflib.pr
Encoding:
Text File  |  1994-08-18  |  3.9 KB  |  190 lines

  1. // UDFLIB.PRG
  2. // Employee Information general library functions
  3. // November, 1993
  4.  
  5. #include "sys.ch"
  6.  
  7. FUNCTION CenterIt(TheData, TheWidth)
  8.    LOCAL ThePad
  9.  
  10.    ThePad := (TheWidth - Len(TheData)) / 2
  11.  
  12.    RETURN Space(Int(ThePad)) + TheData + Space(ThePad + .5) 
  13.  
  14.  
  15. FUNCTION ErrorMsg(TheMsg)
  16.    LOCAL OldCursor, OldColor, TheWidth, TheLeft, TheRight, OldWindow
  17.  
  18.    OldCursor := SetCursor(SC_NONE)
  19.    OldColor  := Error_Color()
  20.    TheWidth  := Max(Len(TheMsg), 23)
  21.    TheLeft   := Int((80 - TheWidth) / 2 - 2)
  22.    TheRight  := TheLeft + TheWidth + 4
  23.  
  24.    OldWindow := Win_Open(8, TheLeft, 14, TheRight, ' Error ')
  25.  
  26.    @  9, TheLeft + 1 CLEAR TO 13, TheRight - 1
  27.    @ 10, TheLeft + 2 SAY CenterIt(TheMsg, TheWidth)
  28.    @ 12, TheLeft + 2 SAY CenterIt('Press Esc to continue', TheWidth)
  29.  
  30.    DO WHILE !InKey(0) = K_ESC
  31.    ENDDO
  32.  
  33.    Win_Close(OldWindow)
  34.    SetColor(OldColor)
  35.    SetCursor(OldCursor)
  36.  
  37.    RETURN FALSE 
  38.  
  39.  
  40. FUNCTION Confirm(TheRow, TheColumn, TheAction, TheMsg, TheMode)
  41.    LOCAL TheChoice, OldCursor, OldColor, OldRow, OldCol, OldWindow, OldMsg
  42.  
  43.    IF !ISLOGICAL(TheMode)
  44.       TheChoice := 1
  45.  
  46.    ELSEIF TheMode
  47.       TheChoice := 1
  48.  
  49.    ELSE
  50.       TheChoice := 2
  51.  
  52.    ENDIF
  53.  
  54.    OldCursor := SetCursor(SC_NONE)
  55.    OldColor := Warning_Color()
  56.    OldRow := Row()
  57.    OldCol := Col()
  58.  
  59.    OldWindow := Win_Open(TheRow, TheColumn, TheRow + 6, TheColumn + 20, ' ' + TheAction + ': ')
  60.    @  TheRow + 2, TheColumn + 4 SAY 'Are you sure?'
  61.    OldMsg := Msg(TheMsg)
  62.  
  63.    @ TheRow + 4, TheColumn + 3  PROMPT ' Yes '
  64.    @ TheRow + 4, TheColumn + 14 PROMPT ' No '
  65.    MENU TO TheChoice
  66.  
  67.    Win_Close(OldWindow)
  68.    Msg(OldMsg)
  69.    SetColor(OldColor)
  70.    SetCursor(OldCursor)
  71.    DevPos(OldRow, OldCol)
  72.  
  73.    RETURN TheChoice = 1 
  74.  
  75.  
  76. FUNCTION Macro(TheMacro)
  77.  
  78.    RETURN &TheMacro 
  79.  
  80.  
  81. FUNCTION Get_Path(TheVar)
  82.    LOCAL ThePath
  83.  
  84.    ThePath := GetEnv(Upper(TheVar))
  85.  
  86.    IF Empty(ThePath)
  87.       ThePath := 'C:\CAVO\SAMPLES\EMPLOYEE\'
  88.  
  89.    ELSEIF !Right(ThePath, 1) == '\'
  90.       ThePath += '\'
  91.  
  92.    ENDIF
  93.  
  94.    RETURN ThePath 
  95.  
  96.  
  97. FUNCTION Sys_Init()
  98.  
  99.    Set(_SET_DELETED, TRUE)
  100.    Set(_SET_SCOREBOARD, FALSE)
  101.    SetCursor(SC_NONE)
  102.  
  103.    RETURN TRUE 
  104.  
  105.  
  106. FUNCTION Build_Msg(TheModule, TheMsg, TheMode)
  107.    LOCAL ThePre, ThePost
  108.  
  109.    IF TheMode = ENTRY_MODE
  110.       ThePre  := 'Enter'
  111.       ThePost := ' - Esc to abort'
  112.  
  113.    ELSEIF TheMode = UPDATE_MODE
  114.       ThePre  := 'Change'
  115.       ThePost := ' - Enter to accept'
  116.  
  117.    ELSEIF TheMode = POSITION_MODE
  118.       ThePre  := 'Enter'
  119.       ThePost := ' - OR - leave blank to browse'
  120.  
  121.    ENDIF
  122.  
  123.    RETURN ThePre                + ;
  124.           ' the '               + ;
  125.           TheModule             + ;
  126.           ' '                   + ;
  127.           TheMsg                + ;
  128.           ThePost               
  129.  
  130.  
  131. FUNCTION Msg(TheMsg)
  132.    LOCAL OldMsg, OldColor, OldRow, OldCol
  133.  
  134.    OldMsg := OddBytes(SaveScreen(24, 0, 24, 79))
  135.  
  136.    IF !ISUNDEFINED(TheMsg)
  137.       OldColor := Message_Color()
  138.       OldRow := Row()
  139.       OldCol := Col()
  140.  
  141.       @ 24, 0 SAY CenterIt(TheMsg, 80)
  142.  
  143.       SetColor(OldColor)
  144.       DevPos(OldRow, OldCol)
  145.    ENDIF
  146.  
  147.    RETURN OldMsg 
  148.  
  149.  
  150. FUNCTION OddBytes(TheString)
  151.    LOCAL TheReturn, TheCount, TheTotal
  152.  
  153.    TheReturn := ""
  154.    TheTotal  := Len(TheString)
  155.  
  156.    FOR TheCount := 1 TO TheTotal STEP 2
  157.       TheReturn += SubStr(TheString, TheCount, 1)
  158.    NEXT
  159.  
  160.    RETURN TheReturn 
  161.  
  162.  
  163. FUNCTION FullString(TheString, Strictly)
  164.  
  165.    IF !ISLOGICAL(Strictly)
  166.    ELSEIF !Strictly
  167.       TheString := AllTrim(TheString)
  168.    ENDIF
  169.  
  170.    RETURN !SUBSET(' ', TheString) 
  171.  
  172.  
  173. FUNCTION RZero(TheString)
  174.    LOCAL TheLength
  175.  
  176.    TheLength := Len(TheString)
  177.    TheString := LTrim(TheString)
  178.  
  179.    RETURN Replicate('0', TheLength - Len(TheString)) + TheString 
  180.  
  181. FUNCTION Read_It(GetList)
  182.    LOCAL OldCursor
  183.  
  184.    OldCursor := SetCursor(SC_NORMAL)
  185.    READ
  186.    SetCursor(OldCursor)
  187.  
  188.    RETURN LastKey()
  189.  
  190.