Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Indent HTML Code

Posted on 1998-11-03
1
Medium Priority
?
870 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 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 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