home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_refer / pad_add / pad_da.txt
Text File  |  1994-01-12  |  1KB  |  41 lines

  1. Function Pad_Data (ByVal SentData As String, AmtSPCS As Integer, Justify As String)
  2.       ' This Function returns the data sent the specified length.
  3.       ' Pass this function Data to pad or truncate, the max length,
  4.       ' L for left justify, R for right justify or C for center justify
  5.       ' EXAMPLE : Pad_Data("JON",10,"R")   = '       JON' (the apostrophes are not returned)
  6.       ' >> Use a MonoSpace Font (Courier or Courier New) <<
  7.  
  8.   SentData = Trim(SentData)
  9.   Pad_Data = SentData
  10.       
  11.   If SentData = "" Then
  12.      Pad_Data = Space$(AmtSPCS)
  13.      Exit Function
  14.   End If
  15.  
  16.   If Len(SentData) > AmtSPCS Then
  17.      Pad_Data = Left$(SentData, AmtSPCS)
  18.      Exit Function
  19.   End If
  20.                    
  21.   Select Case UCase$(Justify)
  22.   
  23.      Case "L"                   ' Left Justify
  24.        SPCS$ = Space$(AmtSPCS)
  25.        Pad_Data = SentData + Left$(SPCS$, (AmtSPCS - Len(SentData)))
  26.      
  27.      Case "R"                   ' Right Justify
  28.        SPCS$ = Space$(AmtSPCS)
  29.        Pad_Data = Left$(SPCS$, (AmtSPCS - Len(SentData))) + SentData
  30.   
  31.      Case "C"                   ' Center Justify
  32.        HlfSpace = Space$((AmtSPCS - Len(SentData)) \ 2)
  33.        Pad_Data = HlfSpace & SentData & HlfSpace
  34.      
  35.      Case Else
  36.        MsgBox "Justification can ONLY be 'L', 'R' or 'C'", 48, "PAD DATA"
  37.  
  38.   End Select
  39.  
  40. End Function
  41.