Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Smart Padding of Spaces

Posted on 2004-09-28
5
Medium Priority
?
252 Views
Last Modified: 2010-04-17
Here's a snippet of a .FRM file:
   Begin VB.Label lblDescription
      BackStyle       =   0  'Transparent
      Caption          =   "lblDescription"
      Height            =   255
      Left                =   120
      TabIndex        =   6
      Top                =   1560
      Width             =   4935
   End
Observe how neatly the "=" are arranged in a vertical axis.Now suppose you're given this list -
BackStyle,Caption,Height,Left,TabIndex,Top & Width.How would you arrange it in precisely the same manner as above - with leading spaces & "="?
0
Comment
Question by:EXwithRaj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Expert Comment

by:Daniel_Iankov
ID: 12168016
If you ate working uder Visual Studio .net  pressing  Ctrl+k and then Ctrl+F should do the trick - this is the Autoformating function, also under Edit->Advanced.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 90 total points
ID: 12169965
You have to use a MonoSpaced Font (like Courier or Courier New) and code such as the below.  If you don't want a hardcoded column width then you have to walk your data set first to determine the width of the largest item.  The code below outputs to Text1 which has its MultiLine property set to true.

Option Explicit

Private Sub Command1_Click()
    Dim separator As String
    Dim colWidth As Integer
    Dim item As Variant
    Dim items As Variant
    Dim values As Variant
   
    Text1.Text = ""
    separator = " = "
    colWidth = 15
    item = "BackStyle|0,Caption|""lbDescription"",Height|255,Left|120,TabIndex|6,Top|1560,Width|4935"
    items = Split(item, ",")
    For Each item In items
        values = Split(item, "|")
        Text1.Text = Text1.Text & trailingSpaces(values(0), colWidth) & separator & values(1) & vbCrLf
    Next
End Sub

Private Function trailingSpaces(ByVal strInput As String, ByVal columnWidth As Integer) As String
    Dim spacesNeeded As Integer
   
    spacesNeeded = columnWidth - Len(strInput)
    If spacesNeeded >= 0 Then
        trailingSpaces = strInput & Space(spacesNeeded) ' pad
    Else
        trailingSpaces = Left(strInput, columnWidth) ' truncate
    End If
End Function
0
 

Author Comment

by:EXwithRaj
ID: 12187739
Hello Daniel,have you misunderstood my question?I am interested in a VB code that would perform the task that I'd explained.But your suggestion to press some hot-keys or set some menu options is indeed mystifying!What are you up to?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12400693
I don't think it should be deleted with points refunded since my solution does what was asked.

~IM
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question