Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

FormatValue - Format a value in a column of given width

Total Hit ( 2826)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 



Click here to copy the following block
Enum FormatColumnAlignment
  Left
  Center
  Right
End Enum

' format a value in a column of given width and with specified alignment
' using the specified pad character

Function FormatValue(ByVal value As String, ByVal width As Integer, _
  ByVal alignment As FormatColumnAlignment, Optional ByVal padchar As Char = _
  " "c) As String
  Function FormatValue(ByVal value As Object, ByVal width As Integer, _
    ByVal alignment As FormatColumnAlignment, Optional ByVal padchar As _
    Char = " "c) As String
  Dim val As String = value.ToString
  Dim len As Integer = val.Length

  Select Case alignment
    Case FormatColumnAlignment.Left
      If len < width Then
        val = val.PadRight(width, padchar)
      ElseIf len > width Then
        val = val.Substring(0, width)
      End If
    Case FormatColumnAlignment.Center
      If len < width Then
        Dim charnum As Integer = len + (width - len) \ 2
        val = val.PadLeft(charnum, padchar).PadRight(width, padchar)
      ElseIf len > width Then
        val = val.Substring((len - width) \ 2, width)
      End If
    Case FormatColumnAlignment.Right
      If len < width Then
        val = val.PadLeft(width, padchar)
      ElseIf len > width Then
        val = val.Substring(len - width)
      End If
  End Select
  Return val
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.