Showing posts with label Miscellaneous. Show all posts
Showing posts with label Miscellaneous. Show all posts

Thursday, December 15, 2011

Description: Explores the directory structure, returns basic file information
Minimum requirements: VB5 Pro or Any Version of VB u have just u need to know ur Controls and how tot use it.
Download: source code
Screenshot:
Directory Browser (8 KB)
Project: Standard EXE
ActiveX Controls/Objects: comctl32.ocx
Controls: File1 (FileListBox), Dir1 (DirListBox), Drive1 (DriveListBox), _
   lvw (ListView), iml (ImageList)
Code:
Option Explicit

Private Sub Form_Load()
    GetFiles ""
End Sub

Private Sub GetFiles(ByVal sPath As String)
    Dim i As Integer
    Dim r As Integer
    Dim li As ListItem
    Dim fp As String
   
    On Error GoTo errLocal
    lvw.ListItems.Clear
    If sPath <> "" Then
        If InStr(sPath, "[") <> 0 Then sPath = Trim(Left(sPath, InStr(sPath, "[") - 1))
        If Right(sPath, 1) = ":" Then sPath = sPath & "\" Else r = 1
        Me.Caption = sPath
        Dir1.Path = sPath
        Dir1.Refresh
        fp = Left(sPath, InStrRev(sPath, "\") - 1)
        If InStr(fp, "\") = 0 Then fp = ""
        lvw.ListItems.Add , fp, ". .", 2, 2
        For i = 0 To Dir1.ListCount - 1
            lvw.ListItems.Add , Dir1.List(i), Mid(Dir1.List(i), Len(Dir1.Path) + 1 + r), 2, 2
        Next
        File1.Path = sPath
        File1.Refresh
        For i = 0 To File1.ListCount - 1
            fp = sPath & "\" & File1.List(i)
            fp = Replace(fp, "\\", "\")
            Set li = lvw.ListItems.Add(, fp, File1.List(i), 3, 3)
            li.SubItems(1) = FileLen(fp)
            li.SubItems(2) = FileDateTime(fp)
        Next
    End If
errBack:
    For i = 0 To Drive1.ListCount - 1
        lvw.ListItems.Add , Drive1.List(i), Drive1.List(i), 1, 1
    Next
    Exit Sub
errLocal:
    MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error"
    GoTo errBack
End Sub

Private Sub Form_Resize()
    lvw.Width = Me.Width - 120
    lvw.Height = Me.Height - 400
End Sub

Private Sub lvw_DblClick()
    If lvw.SelectedItem.Icon <> 3 Then
        GetFiles lvw.SelectedItem.Key
    Else
        MsgBox lvw.SelectedItem.Key
    End If
End Sub

Saturday, December 10, 2011

Choice Selection

Choice selection can easily be programmed in Visual Basic, the control involved is the check box. The status of the check box is either checked or unchecked, and the syntax is Checkbox1.Value=VbChecked or Checkbox1.Value=Unchecked. In the following program , I constructed a three-choice selection list. After the user made the selection, a message box will appear to display the list of choices selected. The code is as follow:  Private Sub Command1_Click()
If Check1.Value = vbChecked And Check2.Value = vbChecked And Check3.Value = vbChecked Then
MsgBox ("You like Reading, Computer and Sports")
ElseIf Check1.Value = vbChecked And Check2.Value = vbChecked And Check3.Value = vbUnchecked Then
MsgBox ("You like Reading and Computer")
ElseIf Check1.Value = vbChecked And Check2.Value = vbUnchecked And Check3.Value = vbChecked Then
MsgBox ("You like Reading and Sports")
ElseIf Check1.Value = vbUnchecked And Check2.Value = vbChecked And Check3.Value = vbChecked Then
MsgBox ("You like Computer and Sports")
ElseIf Check1.Value = vbChecked And Check2.Value = vbUnchecked And Check3.Value = vbChecked Then
MsgBox ("You like Reading and Sports")
ElseIf Check1.Value = vbChecked And Check2.Value = vbUnchecked And Check3.Value = vbUnchecked Then
MsgBox ("You like Reading only ")
ElseIf Check1.Value = vbUnchecked And Check2.Value = vbChecked And Check3.Value = vbUnchecked Then
MsgBox ("You like computer only")
ElseIf Check1.Value = vbUnchecked And Check2.Value = vbUnchecked And Check3.Value = vbChecked Then
MsgBox ("You like Sports only")
Else
MsgBox ("You have no hobby")
End If
End Sub