Solved

Indent HTML Code

Posted on 1998-11-03
1
860 Views
Last Modified: 2006-11-17
Greetings Fellow VB Programmers,
I would like to know to Indent Code ( HTML ).
To turn HTML code like this...
<HTML><HEAD><TITLE></TITLE></HEAD></HTML>
to this...
<HTML>
    <HEAD>
    <TITLE></TITLE>
    </HEAD>
</HTML>
Just a basic Function would be fine.
Just show me how and I will insert the other HTML elements
myself.

Note, that your answer MUST me a function in which I
pass the RichTextBox.Text. Also,
please be kind enough to include comments on how
to add new HTML elements and the tab setting.


Thank you.
0
Comment
Question by:vienna
[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
1 Comment
 
LVL 18

Accepted Solution

by:
deighton earned 200 total points
ID: 1443038
Here is a code indent function I've written for you.

'example call
Private Sub Command1_Click()

    richtextbox2.Text = indent(RichTextBox1.Text)
   
End Sub


Function indent(ByVal sCode As String) As String

    Dim sCommand As String
   
    Dim iPos As Long
    Dim iLen As Long
    Dim iIndent As Long
    Dim bLine As Boolean
   
   
    iLen = Len(sCode)
    iPos = 1
   
    While iPos <= iLen
   
       
       
        If Mid(sCode, iPos, 1) = "<" Then
       
            sCommand = Mid(sCode, iPos, 1)
            iPos = iPos + 1
           
            While Mid(sCode, iPos, 1) <> ">" And iPos <= iLen
           
                sCommand = sCommand & Mid(sCode, iPos, 1)
                iPos = iPos + 1
               
            Wend
            sCommand = UCase(sCommand) & Mid(sCode, iPos, 1)
           
'USE THE OR COMMAND TO EXPAND YOUR LISTS
            If sCommand = "</HTML>" Then 'EXPAND YOUR LIST OF COMMANDS TO CLOSE AN INDENT HERE
           
                iIndent = iIndent - 3  'TAB SPACE = 3 per INDENT HERE
               
            End If
           
            If bLine Then
               
                indent = indent + vbCrLf
               
            End If
           
            indent = indent & String(iIndent, " ") & sCommand
            bLine = True
           
            If sCommand = "<HTML>" Then 'EXPAND YOUR LIST OF COMMANDS TO OPEN AN INDENT HERE
           
                iIndent = iIndent + 3
               
            End If
           
            If iIndent < 0 Then iIndent = 0
           
        Else
       
            indent = indent & Mid(sCode, iPos, 1)
            bLine = True
         
        End If
       
        iPos = iPos + 1
       
    Wend
           
End Function

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

688 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