Compress HTML with VB

Source: Internet
Author: User
Tags save file trim

I wonder if you've used Slim girl, it's a software designed to compress HTML hypertext files and script files. It is said that its compression rate reached more than 15%, I tried, and some files (large) compression rate incredibly reached 50%. I took the compressed file and the original file contrast, hey, it seems to simply put the space, carriage return and line break to remove. It seems that the software is nothing, I use VB can do one. I don't believe you, gentlemen.

First run VB, create a new Standard EXE project, add a text control on the window, two CommandButton controls and a CommonDialog control (file Dialog Control), and then set the Multiline property of the Text1 control to True. The ScrollBars property is set to 3, the other attributes are available by default, and then open the Code window to add the following code:

Option Explicit

Private Sub Form_Load ()

Commondialog1.cancelerror = True

Commondialog1.filter = "Web |*.htm;*.html"

Command1.Caption = "Open"

Command2.Caption = "Save"

End Sub

Private Sub Command1_Click ()

On Error Resume Next

Dim Textline as String

Commondialog1.showopen

If Err <> 32755 Then

Text1 = ""

' Open File

Open commondialog1.filename for Input as #1

Do with not EOF (1)

Line Input #1, Textline

' Remove the left and right spaces and wrap them.

Text1 = Text1 & Trim (textline) & VbCrLf

' If the above sentence is replaced by:

' Text1 = Text1 & Trim (textline)

' That is, remove the space but not the line, so that the compression rate is greater, but its readability is much worse

Loop Close #1

End If

End Sub

Private Sub Command2_Click ()

On Error Resume Next

Commondialog1.showsave

If Err <> 32755 Then

' Save file

Open commondialog1.filename for Output as #1

Print #1, Text1

Close #1

End If

End Sub

Code finished, press F5 run try, open an HTM file (28K, with Dreamwe R), save as another file, take a look, haha, only 13K.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.