ViÕt Code


thdang@tlnet.com.vn

[ Home Trang ®Çu ]  [ ThiÕt kÕ giao diÖn ]

Form1

Option Explicit

Khai b¸o c¸c biÕn toµn côc cho ch­¬ng tr×nh

Public WTitle As String
'
Tiªu ®Ò cña file HTML

Public BeginText As String
'
Dßng v¨n b¶n xuÊt hiÖn ë ®Çu danh s¸ch

Public EndText As String
'
Dßng v¨n b¶n xuÊt hiÖn ë cuèi danh s¸ch

Public AlignText As String
'
Canh lÒ c¸c liªn kÕt, gåm "Left", "Right", "Center"

Public Launch As Integer
'
Xem file sau khi t¹o xong. Gåm 3 gi¸ trÞ: 1-Xem b»ng IE. 2-Xem b»ng Notepad. 3-Kh«ng xem file sau khi t¹o xong

- B¾t ®Çu t¹o file HTML theo ®­êng dÉn tõ lblPath & Text1 ®­îc l­u gi÷ b»ng biÕn F. Më file ®Ó ghi theo d¹ng TextOnly sÏ chøa c¸c HTML tags theo có ph¸p c¸c liªn kÕt (Link).

Do trong file HTML cã sö dông kh¸ nhiÒu dÊu nh¸y kÐp ("). Mµ trong Visual Basic còng cã dïng, ®Ó tr¸nh lÉn lén ta nªn dïng chr(34) thay cho dÊu nh¸y kÐp.

Private Sub cmdCreate_Click()
    On Error GoTo ErrHandle
    Form1.MousePointer = 11
    Dim i As Integer
    Dim k
    Dim F As String
    F = lblPath.Caption & Trim(Text1)
        'LÊy ®­êng dÉn vµ tªn tËp tin
    Open F For Output As #1
    Print #1, "<html>"
    Print #1, "<Title>"; WTitle; "</Title>"
    'Ghi tiªu ®Ò cña trang Web
    Print #1, "<body>"
    Print #1, "<p align="; Chr(34); AlignText; Chr(34); ">"
    Print #1, "<font size="; Chr(34); 5; Chr(34); "><b>"; BeginText & "<br>";
    'Ghi dßng tiªu ®Ò ë ®Çu danh s¸ch
    Print #1, UCase(Dir1.Path); "</b></font></p>"
   
'Ghi ®­êng dÉn
          ' B¾t ®Çu ghi c¸c liªn kÕt

    For i = 0 To List1.ListCount - 1
       
'Ghi c¸c liªn ®Õn c¸c file ®· chän
        If List1.SelCount <> 0 Then
            If List1.Selected(i) = True Then
                Print #1, "<p align="; Chr(34); AlignText; Chr(34);
                Print #1, "><a href="; Chr(34);
                Print #1, List1.List(i); Chr(34);
                Print #1, ">"; File1.List(i); "</a></p>"
            End If
        Else
           
'NÕu kh«ng chän file nµo xem nh­ chän tÊt c¶
            Print #1, "<p align="; Chr(34); AlignText;
            Print #1, Chr(34); "><a href="; Chr(34);
            Print #1, List1.List(i); Chr(34);
            Print #1, ">"; File1.List(i); "</a></p>"
        End If
    Next i
    Print #1, "<p align="; Chr(34); "left"; Chr(34); ">"; EndText
   
'Ghi dßng v¨n b¶n ë cuèi danh s¸ch
    Print #1, "<br>Total: " & _
    IIf(List1.SelCount = 0, List1.ListCount, List1.SelCount) _
    & " link(s)."; "</p>"
   
'In tæng sè c¸c liªn kÕt trong trang Web
    Print #1, "</body></html>"
    Close #1
   
'§ãng danh s¸ch
    Select Case Launch
        Case 1: k = Shell("explorer.exe " & F, vbNormalFocus)
       
'Gäi Internet Explorer
        Case 2: k = Shell("notepad.exe " & F, vbNormalFocus)
       
'Gäi Notepad
    End Select
    Form1.MousePointer = 0
    Text1.SetFocus
    Exit Sub
    ErrHandle:
       
'Xö lý khi cã lçi
        Form1.MousePointer = 0
        MsgBox "Can not create file.", vbCritical
        Drive1.SetFocus
End Sub

'Bá chän tÊt c¶ c¸c file trong danh s¸ch

Private Sub cmdDeselect_Click()
    Dim i As Integer
    For i = List1.ListCount - 1 To 0 Step -1
        List1.Selected(i) = False
    Next i
End Sub

Private Sub cmdExit_Click()
    Unload Me
End Sub

'Chän tÊt c¶ c¸c file trong danh s¸ch

Private Sub cmdSelect_Click()
    Dim i As Integer
    For i = 0 To List1.ListCount - 1
        List1.Selected(i) = True
    Next i
    List1.Refresh
End Sub

'Gäi Form2

Private Sub cmdSettings_Click()
    Form2.Show 1
End Sub

'Xö lý khi ng­êi dïng gâ vµo c¸c ký hiÖu * ? ®Ó läc file

Private Sub Combo1_Change()
    On Error GoTo ErrHandle
    Dim i As Integer
    File1.Pattern = Combo1.Text
    'Add to List Box
    List1.Clear
    For i = 0 To File1.ListCount - 1
        List1.AddItem File1.List(i), i
    Next i
    ErrHandle:
End Sub

'Xö lý khi ng­êi dïng chän c¸c lo¹i file (cã s½n) trong Combobox

Private Sub Combo1_Click()
    Dim i As Integer
    File1.Pattern = Combo1.Text
    'Add to List Box
    AddToList
End Sub

'Xö lý khi ng­êi dïng chän æ ®Üa, th­ môc

Private Sub Dir1_Change()
    File1.Path = Dir1.Path
    lblPath.Caption = IIf(Len(Dir1.Path) = 3, Dir1.Path, Dir1.Path + "\")
    AddToList
End Sub

Private Sub Drive1_Change()
    On Error GoTo ErrHandle
    Dir1.Path = Drive1.Drive
    ErrHandle:
End Sub

Private Sub Form_Load()
    Me.Caption = "Indexer - " & "v" & App.Major & "." & App.Minor & App.Revision
    WTitle = "Indexer - List of Directory"
    BeginText = ""
    EndText = ""
    AlignText = "Left"
    Launch = 1
    File1.Path = Dir1.Path
    lblPath.Caption = IIf(Len(Dir1.Path) = 3, Dir1.Path, Dir1.Path + "\")
    AddToList
End Sub

'N¹p c¸c file tõ FileListBox sang ListBox, ®Ó tr¸nh t×nh tr¹ng xuÊt hiÖn liªn kÕt ®Õn chÝnh file võa t¹o (khi file nµy ®· ®­îc t¹o ra tr­íc ®ã) t«i ph¶i dïng thªm Kill() nÕu file ®ã trïng tªn víi file s¾p t¹o.

Public Sub AddToList()
    Dim i As Integer
    On Error Resume Next
    Dim F As String
    F = lblPath.Caption & Trim(Text1)
    Kill (F)
    File1.Refresh
    List1.Clear
    For i = 0 To File1.ListCount - 1
        List1.AddItem File1.List(i), i
    Next i
End Sub

'Tù ®éng select v¨n b¶n mçi khi Textbox nhËn ®­îc focus, ®Ó tiÖn cho ng­êi dïng.

Private Sub Text1_GotFocus()
    Text1.SelStart = 0
    Text1.SelLength = Len(Text1)
End Sub

Form2

Option Explicit

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub cmdOK_Click()
    Form1.WTitle = txtTitle.Text

    '
G¸n biÕn WTitle b»ng néi dung cña txtTitle
    Form1.BeginText = txtBegin.Text
   
'G¸n biÕn BeginText b»ng néi dung cña txtBegin
    Form1.EndText = txtEnd.Text

    '
G¸n biÕn EndText b»ng néi dung cña txtEnd
    Form1.Launch = IIf(optIE.Value, 1, IIf(optNod.Value, 2, 3))
    'NÕu optIE ®­îc chän th× g¸n Launch = 1, optNod -> 2, optNone -> 3
    Form1.AlignText = cmbAlign.Text
    Unload Me
End Sub

'Tù ®éng select v¨n b¶n mçi khi Textbox nhËn ®­îc focus, ®Ó tiÖn cho ng­êi dïng.

Private Sub txtBegin_GotFocus()
    txtBegin.SelStart = 0
    txtBegin.SelLength = Len(txtBegin)
End Sub

Private Sub txtEnd_GotFocus()
    txtEnd.SelStart = 0
    txtEnd.SelLength = Len(txtEnd)
End Sub

Private Sub txtTitle_GotFocus()
    txtTitle.SelStart = 0
    txtTitle.SelLength = Len(txtTitle)
End Sub

Ch­¬ng tr×nh mÉu

[ Home Trang ®Çu ]  [ ThiÕt kÕ giao diÖn ]


chuÒ nhâòt, thaìng hai 03, 2002 05:50:49 CH
NguyÔn Hå Thiªn §¨ng


PcLeHoan 1996 - 2002
Mirror : http://www.pclehoan.com
Mirror : http://www.lehoanpc.net

Mirror : http://www.ktlehoan.com