VERSION 4.00
Begin VB.Form frmFile 
   ClientHeight    =   4095
   ClientLeft      =   2460
   ClientTop       =   1995
   ClientWidth     =   6075
   Height          =   4500
   Left            =   2400
   LinkTopic       =   "Form2"
   ScaleHeight     =   4095
   ScaleWidth      =   6075
   Top             =   1650
   Width           =   6195
   Begin VB.CommandButton cmdFcancel 
      Caption         =   "Cancel"
      Height          =   372
      Left            =   4920
      TabIndex        =   5
      Top             =   3600
      Width           =   852
   End
   Begin VB.CommandButton cmdFopen 
      Caption         =   "Open"
      Height          =   372
      Left            =   3960
      TabIndex        =   4
      Top             =   3600
      Width           =   852
   End
   Begin VB.DriveListBox drvList 
      Height          =   276
      Left            =   120
      TabIndex        =   3
      Top             =   120
      Width           =   2172
   End
   Begin VB.TextBox txtFileName 
      Height          =   285
      Left            =   2400
      TabIndex        =   2
      Top             =   3120
      Width           =   3492
   End
   Begin VB.FileListBox filList 
      Height          =   2580
      Left            =   2400
      Pattern         =   "*.txt"
      TabIndex        =   1
      Top             =   120
      Width           =   3495
   End
   Begin VB.DirListBox dirList 
      Height          =   3492
      Left            =   120
      TabIndex        =   0
      Top             =   480
      Width           =   2172
   End
End
Attribute VB_Name = "frmFile"
Attribute VB_Creatable = False
Attribute VB_Exposed = False



Private Sub drvList_error(dataerr As Integer, response As Integer)

End Sub
Private Sub cmdFcancel_Click()
'Close frmFile.
    frmFile.Hide
    Unload frmFile
End Sub


Private Sub cmdFopen_Click()
'Set the selected path and close frmFile.
    If PathCheck = 0 Then
        PathInfo.Drv = drvList.Drive
        PathInfo.Dir = dirList.Path
        PathInfo.File = filList.filename
        ChckPath = Right(txtFileName.Text, 5)
        ChckPath = Left(ChckPath, 1)
        If ChckPath = "*" Then
            MB_Options = vbCritical
            If PathTxt.Check = 0 Then
                MsgBox "Choose a Text file.", MB_Options, "Error Message"
            ElseIf PathBmp.Check = 1 Then
                MsgBox "Choose a BMP file.", MB_Options, "Error Message"
            End If
            Exit Sub
        End If
        If filList.Pattern = "*.txt" Then
        'If text file was selected.
            frmMain.txtFontFilename.Text = txtFileName.Text
            PathTxt = PathInfo
        ElseIf filList.Pattern = "*.bmp" Then
        'If bitmap file was selected.
            On Error GoTo ErrFOpen:
            'Go to ErrFOpen: if an error occurred.
            frmMain.picBmp.Picture = LoadPicture(txtFileName.Text)
            frmMain.txtBmpFilename.Text = txtFileName.Text
            'Load the bitmap file to frmBMP,
            'Fit the width and the hight to the bitmap file
            frmBMP.Height = 0
            frmBMP.picBmp.Picture = LoadPicture(txtFileName.Text)
            frmBMP.picBmp.Top = 0
            frmBMP.picBmp.Left = 0
            frmBMP.Height = frmBMP.Height + frmBMP.picBmp.Height
            frmBMP.Width = frmBMP.picBmp.Width
            PathBmp = PathInfo
        End If
        frmFile.Hide
        Unload frmFile
    End If
        Exit Sub
ErrFOpen:
    MB_Options = vbCritical
    MsgBox "Bitmap Load Error.", MB_Options, "Error Message"
End Sub
Private Sub Drive1_Change()
    Dir
End Sub

Private Sub dirList_Change()
'Set a selected path to filList.
    If PathCheck = 0 Then
        filList.Path = dirList.Path
    End If
End Sub

Private Sub drvList_Change()
'Set a selected drive to drfList.
    If PathCheck = 0 Then
        On Error GoTo drvListError:
         'Go to drvListError: if an error occurred.
        dirList.Path = drvList.Drive
        Exit Sub

drvListError:
    End If
End Sub
Private Sub filList_Click()
'Set a selected file name to txtFileName.
    If Right(dirList.Path, 1) = "\" Then
        txtFileName.Text = dirList.Path + filList.filename
    Else
        txtFileName.Text = dirList.Path + "\" + filList.filename
    End If
End Sub

Private Sub filList_DblClick()
'Set a selected path and close frmFile.
    If Right(dirList.Path, 1) = "\" Then
    'Set a selected file name to txtFileName.
        txtFileName.Text = dirList.Path + filList.filename
    Else
        txtFileName.Text = dirList.Path + "\" + filList.filename
    End If
    If PathCheck = 0 Then
        PathInfo.Drv = drvList.Drive
        PathInfo.Dir = dirList.Path
        PathInfo.File = filList.filename
        If filList.Pattern = "*.txt" Then
        'If text file was selected.
            frmMain.txtFontFilename.Text = txtFileName.Text
            PathTxt = PathInfo
        ElseIf filList.Pattern = "*.bmp" Then
        'If bitmap file was selected.
            On Error GoTo ErrFOpen:
            'Go to ErrFOpen: if an error occurred.
            frmMain.picBmp.Picture = LoadPicture(txtFileName.Text)
            frmMain.txtBmpFilename.Text = txtFileName.Text
            'Load the bitmap file to frmBMP,
            'Fit the width and the hight to the bitmap file
            frmBMP.Height = 0
            frmBMP.picBmp.Picture = LoadPicture(txtFileName.Text)
            frmBMP.picBmp.Top = 0
            frmBMP.picBmp.Left = 0
            frmBMP.Height = frmBMP.Height + frmBMP.picBmp.Height
            frmBMP.Width = frmBMP.picBmp.Width
            PathBmp = PathInfo
        End If
        frmFile.Hide
        Unload frmFile
ErrFOpen:
    End If
End Sub
Private Sub Form_Load()
'Initialize frmFile.
    Dim i As Integer
    
    Me.Left = Screen.Width / 2 - Me.Width / 2
    Me.Top = Screen.Height / 2 - Me.Height / 2
    
    frmFile.Show
    Load frmBMP
    PathCheck = 1
    If PathBmp.Check = 1 Then
    'Select bitmap files only.
        frmFile.filList.Pattern = "*.bmp"
        frmFile.Caption = "File Select (*.bmp)"
        frmFile.txtFileName.Text = "*.bmp"
        PathInfo = PathBmp
    ElseIf PathTxt.Check = 1 Then
    'Select text files only.
        frmFile.filList.Pattern = "*.txt"
        frmFile.Caption = "File Select (*.txt)"
        frmFile.txtFileName.Text = "*.txt"
        PathInfo = PathTxt
    End If
    
    If PathInfo.Drv <> "0" Then
    'Set the last selected file.
        On Error GoTo Error0:
        'Go to Error0: if an error occurred.
            drvList.Drive = PathInfo.Drv
        On Error GoTo Error1:
        'Go to Error1: if an error occurred.
            dirList.Path = PathInfo.Dir
            filList.Path = PathInfo.Dir
        For i = 0 To filList.ListCount
            If filList.List(i) = PathInfo.File Then
                filList.ListIndex = i
            End If
        Next
    End If
    PathCheck = 0
    Exit Sub

'Error handling.
Error0:
    PathCheck = 0
    Exit Sub
Error1:
    dirList.Path = PathInfo.Drv
    filList.Path = PathInfo.Drv
    PathCheck = 0
End Sub
Private Sub txtFileName_KeyPress(KeyAscii As Integer)
'Set a selected path and close frmFile.
    If PathCheck = 0 Then
       'Press Enter key
        If KeyAscii = 13 Then
            PathInfo.Drv = drvList.Drive
            PathInfo.Dir = dirList.Path
            PathInfo.File = filList.filename
            ChckPath = Right(txtFileName.Text, 3)
            If PathTxt.Check = 1 Then
                If ChckPath <> "txt" And ChckPath <> "TXT" Then
                    MB_Options = vbCritical
                    MsgBox "Choose a Text file.", MB_Options, "Error Message"
                    Exit Sub
                End If
            ElseIf PathBmp.Check = 1 Then
                If ChckPath <> "bmp" And ChckPath <> "BMP" Then
                    MB_Options = vbCritical
                    MsgBox "Choose a Text file.", MB_Options, "Error Message"
                    Exit Sub
                End If
            End If
            If filList.Pattern = "*.txt" Then
            'If text file was selected.
                frmMain.txtFontFilename.Text = txtFileName.Text
                PathTxt = PathInfo
            ElseIf filList.Pattern = "*.bmp" Then
            'If bitmap file was selected.
                On Error GoTo ErrFOpen:
                'Go to ErrFOpen: if an error occurred.
                frmMain.picBmp.Picture = LoadPicture(txtFileName.Text)
                frmMain.txtBmpFilename.Text = txtFileName.Text
                'Load the bitmap file to frmBMP,
                'Fit the width and the hight to the bitmap file
                frmBMP.Height = 0
                frmBMP.picBmp.Picture = LoadPicture(txtFileName.Text)
                frmBMP.picBmp.Top = 0
                frmBMP.picBmp.Left = 0
                frmBMP.Height = frmBMP.Height + frmBMP.picBmp.Height
                frmBMP.Width = frmBMP.picBmp.Width
                PathBmp = PathInfo
            End If
            frmFile.Hide
            Unload frmFile
        End If
    End If
        Exit Sub
        
ErrFOpen:
    MB_Options = vbCritical
    MsgBox "Bitmap Load Error.", MB_Options, "Error Message"

End Sub

