VERSION 5.00
Begin VB.Form frmBadFiles 
   Caption         =   "View/Edit Bad File List"
   ClientHeight    =   5025
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7785
   Icon            =   "frmBadFiles.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   5025
   ScaleWidth      =   7785
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton command1 
      Caption         =   "&Close Window"
      Height          =   495
      Index           =   6
      Left            =   600
      TabIndex        =   7
      Top             =   4320
      Width           =   6375
   End
   Begin VB.CommandButton command1 
      Caption         =   "Move to &Bottom of list"
      Height          =   375
      Index           =   5
      Left            =   2805
      TabIndex        =   4
      Top             =   3720
      Width           =   2175
   End
   Begin VB.CommandButton command1 
      Caption         =   "Move to &Top of list"
      Height          =   375
      Index           =   4
      Left            =   2805
      TabIndex        =   3
      Top             =   3240
      Width           =   2175
   End
   Begin VB.CommandButton command1 
      Caption         =   "Move D&own One in list"
      Height          =   375
      Index           =   3
      Left            =   5445
      TabIndex        =   6
      Top             =   3720
      Width           =   2175
   End
   Begin VB.CommandButton command1 
      Caption         =   "Move &Up One in list"
      Height          =   375
      Index           =   2
      Left            =   5445
      TabIndex        =   5
      Top             =   3240
      Width           =   2175
   End
   Begin VB.CommandButton command1 
      Caption         =   "&Delete File"
      Height          =   375
      Index           =   1
      Left            =   165
      TabIndex        =   2
      Top             =   3720
      Width           =   2175
   End
   Begin VB.CommandButton command1 
      Caption         =   "&Add File"
      Height          =   375
      Index           =   0
      Left            =   165
      TabIndex        =   1
      Top             =   3240
      Width           =   2175
   End
   Begin VB.ListBox List1 
      Height          =   2790
      ItemData        =   "frmBadFiles.frx":0442
      Left            =   120
      List            =   "frmBadFiles.frx":0444
      TabIndex        =   0
      Top             =   120
      Width           =   7575
   End
End
Attribute VB_Name = "frmBadFiles"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private changes_occured As Boolean

Private Sub SaveListBoxToFile()
On Error GoTo SaveListBoxToFileError

 Dim fso As FileSystemObject
 Dim textfile As File
 Dim a_textstream As TextStream
 Dim path As String
 Set fso = CreateObject("Scripting.FileSystemObject")
 path = App.path
 If Right$(path, 1) <> "\" Then path = path & "\"
 'file does not exist, so create it
 If AFDTextFileExists = False Then fso.CreateTextFile (path & SAVE_TO_FILE)
 Set textfile = fso.GetFile(path & SAVE_TO_FILE)
 Set a_textstream = textfile.OpenAsTextStream(ForWriting)
 
 If List1.ListCount > 0 Then
  Dim i As Integer
  For i = 0 To (List1.ListCount - 1)
   a_textstream.WriteLine List1.List(i)
   DoEvents
  Next
 a_textstream.Close
 Set fso = Nothing
 Else 'there is nothing in the list box (delete the file)
 a_textstream.Close
 Set fso = Nothing
 Set fso = CreateObject("Scripting.FileSystemObject")
   If fso.FileExists(path & SAVE_TO_FILE) Then
    fso.DeleteFile (path & SAVE_TO_FILE)
   End If
 End If
 
Exit Sub
SaveListBoxToFileError:
MsgBox "There was an error." & vbNewLine & vbNewLine & "Error Number: " & Err.Number & vbNewLine & "Error Description: " & Err.Description & vbNewLine & "Occured in function: SaveListBoxToFile" & vbNewLine, vbCritical + vbOKOnly
End Sub

Private Sub Command1_Click(Index As Integer)

Dim tmp_string As String
Dim old_index As Long

Select Case Index

Case 0 'Add File Clicked
 If changes_occured = True Then 'changes occured, save new contents to file
  SaveListBoxToFile
 End If
 
 AddAFileManually False, Me
 LoadFileIntoListBox
 changes_occured = True
 
Case 1 'Delete File Clicked
 If List1.ListIndex <> -1 Then 'as long as there is something selected
  old_index = List1.ListIndex
  List1.RemoveItem List1.ListIndex
  If List1.ListCount > 0 Then
   If old_index <> 0 Then
    List1.ListIndex = old_index - 1 'move to the one before
   Else
    List1.ListIndex = 0 'move to the one after
   End If
  End If
  changes_occured = True
 End If
 
Case 2 'Move Up One in list Clicked
 If List1.ListIndex <> -1 And List1.ListIndex <> 0 Then
  tmp_string = List1.Text
  List1.List(List1.ListIndex) = List1.List(List1.ListIndex - 1)
  List1.List(List1.ListIndex - 1) = tmp_string
  List1.ListIndex = List1.ListIndex - 1
  changes_occured = True
 End If
 
Case 3 'Move Down One in list Clicked
 If List1.ListIndex <> -1 And List1.ListIndex <> (List1.ListCount - 1) Then
  tmp_string = List1.Text
  List1.List(List1.ListIndex) = List1.List(List1.ListIndex + 1)
  List1.List(List1.ListIndex + 1) = tmp_string
  List1.ListIndex = List1.ListIndex + 1
  changes_occured = True
 End If
 
Case 4 'Move to Top of list Clicked
 If List1.ListIndex <> -1 And List1.ListIndex <> 0 Then
  tmp_string = List1.Text
  List1.List(List1.ListIndex) = List1.List(0)
  List1.List(0) = tmp_string
  List1.ListIndex = 0
  changes_occured = True
 End If
 
Case 5 'Move to Bottom of list Clicked
 If List1.ListIndex <> -1 And List1.ListIndex <> (List1.ListCount - 1) Then
  tmp_string = List1.Text
  List1.List(List1.ListIndex) = List1.List(List1.ListCount - 1)
  List1.List(List1.ListCount - 1) = tmp_string
  List1.ListIndex = List1.ListCount - 1
  changes_occured = True
 End If
 
Case 6 'All Done Clicked
 If changes_occured = True Then
  'write listbox contents out to new file
  SaveListBoxToFile
 End If
 Unload Me
End Select

End Sub

Private Sub Form_Load()

changes_occured = False

If AFDTextFileExists = False Then
 If MsgBox("Bad file list does not exist. Create it?", vbYesNo + vbQuestion) = vbYes Then
  CreateAFDTextFile
 End If
End If

If AFDTextFileExists = True Then 'file exists
 'enable the command buttons
 command1(0).Enabled = True
 command1(1).Enabled = True
 command1(2).Enabled = True
 command1(3).Enabled = True
 command1(4).Enabled = True
 command1(5).Enabled = True
 'load the file into the listbox
  LoadFileIntoListBox
Else 'file does not exist
 'disable the command buttons
 command1(0).Enabled = False
 command1(1).Enabled = False
 command1(2).Enabled = False
 command1(3).Enabled = False
 command1(4).Enabled = False
 command1(5).Enabled = False
End If

End Sub

Private Sub LoadFileIntoListBox()
On Error GoTo LoadFileIntoListBoxError

List1.Clear

Dim fso As FileSystemObject
Dim textfile As File
Dim a_textstream As TextStream
Set fso = CreateObject("Scripting.FileSystemObject")
Dim path As String
path = App.path
If Right$(path, 1) <> "\" Then path = path & "\"

If AFDTextFileExists = False Then 'file does not exist, so create it
 fso.CreateTextFile (path & SAVE_TO_FILE)
End If

Set textfile = fso.GetFile(path & SAVE_TO_FILE)
Set a_textstream = textfile.OpenAsTextStream(ForReading)

'lock the listbox from screen-updates
LockWindowUpdate List1.hwnd

Do Until a_textstream.AtEndOfStream = True
 List1.AddItem a_textstream.ReadLine
Loop

'Unlock the listbox
LockWindowUpdate 0&

a_textstream.Close
Set fso = Nothing

If List1.ListCount > 0 Then
 List1.ListIndex = 0
End If

Exit Sub
LoadFileIntoListBoxError:
 MsgBox "There was an error." & vbNewLine & vbNewLine & "Error Number: " & Err.Number & vbNewLine & "Error Description: " & Err.Description & vbNewLine & "Occured in function: LoadFileIntoListBox" & vbNewLine, vbCritical + vbOKOnly
End Sub

Private Sub Form_Resize()
 'Listbox
 List1.Left = (8 * Screen.TwipsPerPixelX)
 List1.Top = (8 * Screen.TwipsPerPixelX)
 If (Me.Width - (22 * Screen.TwipsPerPixelX)) > 0 Then List1.Width = Me.Width - (22 * Screen.TwipsPerPixelX)
 If (Me.Height - (156 * Screen.TwipsPerPixelY)) > 0 Then List1.Height = Me.Height - (156 * Screen.TwipsPerPixelY)
 
 'All Done Button
 command1(6).Width = CInt(0.82 * List1.Width)
 If (Me.Height - (67 * Screen.TwipsPerPixelY)) > 0 Then command1(6).Top = Me.Height - (74 * Screen.TwipsPerPixelY)
 If (((Me.Width - command1(6).Width) / 2) - (5 * Screen.TwipsPerPixelX)) > 0 Then command1(6).Left = ((Me.Width - command1(6).Width) / 2) - (5 * Screen.TwipsPerPixelX)
 
 'Add File Button
 command1(0).Width = CInt(0.2871 * List1.Width)
 If (Me.Height - (139 * Screen.TwipsPerPixelY)) > 0 Then command1(0).Top = Me.Height - (139 * Screen.TwipsPerPixelY)
 command1(0).Left = (11 * Screen.TwipsPerPixelX)
  
 'Delete File Button
 command1(1).Width = CInt(0.2871 * List1.Width)
 If (Me.Height - (107 * Screen.TwipsPerPixelY)) > 0 Then command1(1).Top = Me.Height - (107 * Screen.TwipsPerPixelY)
 command1(1).Left = (11 * Screen.TwipsPerPixelX)
 
 'Move to top of list button
 command1(4).Width = CInt(0.2871 * List1.Width)
 If (Me.Height - (139 * Screen.TwipsPerPixelY)) > 0 Then command1(4).Top = Me.Height - (139 * Screen.TwipsPerPixelY)
 If (((Me.Width - command1(4).Width) / 2) - (5 * Screen.TwipsPerPixelX)) > 0 Then command1(4).Left = ((Me.Width - command1(4).Width) / 2) - (5 * Screen.TwipsPerPixelX)
  
 'Move to bottom of list button
 command1(5).Width = CInt(0.2871 * List1.Width)
 If (Me.Height - (107 * Screen.TwipsPerPixelY)) > 0 Then command1(5).Top = Me.Height - (107 * Screen.TwipsPerPixelY)
 If (((Me.Width - command1(5).Width) / 2) - (5 * Screen.TwipsPerPixelX)) > 0 Then command1(5).Left = ((Me.Width - command1(5).Width) / 2) - (5 * Screen.TwipsPerPixelX)
  
 'Move up one in list button
 command1(2).Width = CInt(0.2871 * List1.Width)
 If (Me.Height - (139 * Screen.TwipsPerPixelY)) > 0 Then command1(2).Top = Me.Height - (139 * Screen.TwipsPerPixelY)
 If (Me.Width - command1(2).Width - (19 * Screen.TwipsPerPixelX)) > 0 Then command1(2).Left = Me.Width - command1(2).Width - (19 * Screen.TwipsPerPixelX)
 
 'Move down one in list button
 command1(3).Width = CInt(0.2871 * List1.Width)
 If (Me.Height - (107 * Screen.TwipsPerPixelY)) > 0 Then command1(3).Top = Me.Height - (107 * Screen.TwipsPerPixelY)
 If (Me.Width - command1(3).Width - (19 * Screen.TwipsPerPixelX)) > 0 Then command1(3).Left = Me.Width - command1(3).Width - (19 * Screen.TwipsPerPixelX)
 
End Sub