home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / fileli1a / frmlistf.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-10-08  |  9.7 KB  |  317 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "File List tool"
  4.    ClientHeight    =   3270
  5.    ClientLeft      =   60
  6.    ClientTop       =   630
  7.    ClientWidth     =   6750
  8.    LinkTopic       =   "Form1"
  9.    MaxButton       =   0   'False
  10.    ScaleHeight     =   3270
  11.    ScaleWidth      =   6750
  12.    StartUpPosition =   2  'CenterScreen
  13.    Begin VB.TextBox Text1 
  14.       Height          =   285
  15.       Left            =   0
  16.       TabIndex        =   1
  17.       Top             =   2640
  18.       Width           =   6735
  19.    End
  20.    Begin VB.ListBox List1 
  21.       Height          =   2595
  22.       ItemData        =   "FrmListFiles.frx":0000
  23.       Left            =   0
  24.       List            =   "FrmListFiles.frx":0002
  25.       MultiSelect     =   2  'Extended
  26.       OLEDropMode     =   1  'Manual
  27.       TabIndex        =   0
  28.       TabStop         =   0   'False
  29.       Top             =   0
  30.       Width           =   6735
  31.    End
  32.    Begin VB.Label Label1 
  33.       Caption         =   "Total Files"
  34.       Height          =   255
  35.       Left            =   0
  36.       TabIndex        =   2
  37.       Top             =   3000
  38.       Width           =   6735
  39.    End
  40.    Begin VB.Menu File 
  41.       Caption         =   "&File"
  42.       Begin VB.Menu NewList 
  43.          Caption         =   "&New"
  44.          Shortcut        =   ^N
  45.       End
  46.       Begin VB.Menu OpenList 
  47.          Caption         =   "&Open"
  48.          Shortcut        =   ^O
  49.       End
  50.       Begin VB.Menu Reopen 
  51.          Caption         =   "ReOpen"
  52.          Begin VB.Menu Clear 
  53.             Caption         =   "Clear List"
  54.          End
  55.          Begin VB.Menu mnuSepMRU 
  56.             Caption         =   "-"
  57.          End
  58.          Begin VB.Menu mnuReopenSub 
  59.             Caption         =   "None"
  60.             Enabled         =   0   'False
  61.             Index           =   0
  62.          End
  63.       End
  64.       Begin VB.Menu Save 
  65.          Caption         =   "&Save"
  66.          Shortcut        =   ^S
  67.       End
  68.       Begin VB.Menu mnuSep 
  69.          Caption         =   "-"
  70.       End
  71.       Begin VB.Menu Exit 
  72.          Caption         =   "E&xit"
  73.          Shortcut        =   ^Q
  74.       End
  75.    End
  76.    Begin VB.Menu Help 
  77.       Caption         =   "&Help"
  78.       Begin VB.Menu LstFiles 
  79.          Caption         =   "&With List Files"
  80.       End
  81.       Begin VB.Menu About 
  82.          Caption         =   "&About"
  83.       End
  84.    End
  85. Attribute VB_Name = "Form1"
  86. Attribute VB_GlobalNameSpace = False
  87. Attribute VB_Creatable = False
  88. Attribute VB_PredeclaredId = True
  89. Attribute VB_Exposed = False
  90. Dim Dirty As Boolean, MRUNum As Integer
  91. Private Sub AddToMRUX(FileNam As String)
  92. Dim X As Integer
  93. ' x = 1 MRU Number
  94. For X = 1 To MRUNum
  95.     ' Checks for duplicates
  96.     If FileNam = MRUX(X) Then Exit Sub
  97. ' Opens MRU data file
  98. Open App.Path + "\MRU.dat" For Output As #1
  99.     ' Puts new file name if it exists
  100.     If FileExists(FileNam) Then Print #1, FileNam
  101.     For X = 1 To MRUNum
  102.         ' Puts other filenames if they exist
  103.         If X <> 15 Then If FileExists(MRUX(X)) Then Print #1, MRUX(X)
  104.     Next
  105. Close
  106. ' Keeps track of number of MRU
  107. If MRUNum <> 15 Then MRUNum = MRUNum + 1
  108. ' Clears displayed MRU list
  109. mnuReopenSub(0).Caption = "None"
  110. mnuReopenSub(0).Enabled = False
  111. For Num = 1 To mnuReopenSub.Count - 1
  112.     mnuReopenSub(Num).Visible = False
  113. ' Displays New MRU List
  114. DisplayMRU
  115. End Sub
  116. Private Sub CreateReopenItem(ByVal menu_caption As String)
  117. Static Menuro_Num As Integer
  118. ' Checks first MRU line to see if it's got anything (is enabled if it has anything
  119. If mnuReopenSub(0).Enabled Then
  120.     ' Tracking counter
  121.     Menuro_Num = Menuro_Num + 1
  122.     ' Loads new menu item
  123.     Load mnuReopenSub(Menuro_Num)
  124.     ' Enables First
  125.     mnuReopenSub(0).Enabled = True
  126.     ' Resets counter
  127.     Menuro_Num = 0
  128. End If
  129. ' Puts MRU caption
  130. mnuReopenSub(Menuro_Num).Caption = menu_caption
  131. ' Tracker
  132. Num = Menuro_Num
  133. End Sub
  134. Private Sub DisplayMRU()
  135. Dim X As Integer
  136. ' Opens MRU datafile
  137. Open App.Path + "\MRU.dat" For Input As #1
  138.     X = 1
  139.     Do While Not EOF(1)
  140.         ' Inputs MRU data
  141.         Line Input #1, MRUX(X)
  142.         ' Tracking counter
  143.         X = X + 1
  144.     Loop
  145. Close
  146. ' Tracks MRU Number
  147. MRUNum = X - 1
  148. For X = 1 To MRUNum
  149.     ' If file exists, put menu item
  150.     If FileExists(MRUX(X)) Then CreateReopenItem (ExtractFileName(MRUX(X)))
  151. End Sub
  152. Private Sub OpenMyList(FileNam As String)
  153. Dim Tot As String
  154. ' Checks to see if file exists
  155. If FileExists(FileNam) Then
  156.     ' Clears list
  157.     List1.Clear
  158.     ' Gets file number
  159.     FF = FreeFile
  160.     ' Opens file
  161.     Open FileNam For Input As #FF
  162.         Do While Not EOF(FF)
  163.             ' Gets data
  164.             Line Input #FF, Lne
  165.             ' Adds data to list
  166.             List1.AddItem Lne
  167.         Loop
  168.     Close
  169.     ' Gets total number of files
  170.     Tot = List1.ListCount
  171.     ' Displays total
  172.     Label1.Caption = Tot + " Total Files"
  173.     ' Adds file to MRU list
  174.     AddToMRUX (FileNam)
  175.     ' If file doesn't exist, display warning
  176.     MsgBox "That file does not exist", vbExclamation, "File Not Found!"
  177. End If
  178. End Sub
  179. Private Sub About_Click()
  180. ' About this program
  181. MsgBox "If you find this program or source code useful, drop me a line at (phillip@softhome.net" & vbNewLine & _
  182.         "If you use this code, please site me in the credits.  Also tell me if you have any" & vbNewLine & _
  183.         "suggestions or bug (fixes).", vbInformation, "About this Program"
  184. End Sub
  185. Private Sub Clear_Click()
  186. Dim None As String
  187. ' Resets first MRU entry
  188. mnuReopenSub(0).Caption = "None"
  189. mnuReopenSub(0).Enabled = False
  190. ' Resets other MRU entries
  191. For Num = 1 To mnuReopenSub.Count - 1
  192.     mnuReopenSub(Num).Visible = False
  193. None = ""
  194. ' Writes blank MRU datafile
  195. Open App.Path + "\MRU.dat" For Output As #1
  196. Close
  197. ' Resets MRU tracking number
  198. MRUNum = 0
  199. End Sub
  200. Private Sub Exit_Click()
  201. ' Unloads form
  202. Unload Me
  203. End Sub
  204. Private Sub Form_Load()
  205. 'Displays MRU
  206. DisplayMRU
  207. End Sub
  208. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  209. Dim Response As String
  210. ' If list has changed it is dirty
  211. If Dirty Then
  212.     ' Prompts to save "dirty" list
  213.     Response = MsgBox("Do you want to save this list", vbYesNoCancel, "List has changed!")
  214.     ' Responds to user input
  215.     Select Case Response
  216.         Case vbYes
  217.             'Save the list
  218.             Save_Click
  219.         Case vbNo
  220.             ' Don't save list
  221.             Cancel = False
  222.         Case vbCancel
  223.             ' Cancels quit
  224.             Cancel = True
  225.     End Select
  226. End If
  227. End Sub
  228. Private Sub List1_DblClick()
  229. ' Removes list item
  230. List1.RemoveItem (List1.ListIndex)
  231. ' List has changed, it is "Dirty"
  232. Dirty = True
  233. End Sub
  234. Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  235. Dim fname As Variant, lFileSize As String
  236. For Each fname In Data.Files
  237.     ' Adds formatted filename and file size to list
  238.     List1.AddItem ExtractFileName(fname + ": " + FormatFileSize(FileLen(fname)))
  239. ' Indicate we did nothing with the files.
  240. Effect = vbDropEffectNone
  241. ' List has changed, it is "Dirty"
  242. Dirty = True
  243. End Sub
  244. Private Sub LstFiles_Click()
  245. ' Help with this program
  246. MsgBox "This program lets you create lists of files by droping the files" & vbNewLine & _
  247.         "onto the listbox.  You can search the list by typing into the" & vbNewLine & _
  248.         "textbox, the matching files will be selected in the textbox." & vbNewLine & vbNewLine & _
  249.         "Remove list items by double clicking on them." & vbNewLine & vbNewLine & _
  250.         "You can open previously made lists with the MRU provided on the" & vbNewLine & _
  251.         "File>ReOpen> Menu.  To Clear the MRU Press Clear List.", vbInformation, "Help with listfiles"
  252.         
  253. End Sub
  254. Private Sub mnuReopenSub_Click(Index As Integer)
  255. ' Opens MRU Selected
  256. OpenMyList (MRUX(Index + 1))
  257. End Sub
  258. Private Sub NewList_Click()
  259. ' Clears list
  260. List1.Clear
  261. ' New lists aren't "Dirty"
  262. Dirty = False
  263. End Sub
  264. Private Sub OpenList_Click()
  265. Dim FF As Integer, FileNam As String, Lne As String, Tot As String
  266. ' Checks to see if list has been changed
  267. If Dirty Then
  268.     ' Prompts to save
  269.     Response = MsgBox("Do you want to save this list", vbYesNoCancel, "List has changed!")
  270.     ' Responds to user input
  271.     Select Case Response
  272.         Case vbYes
  273.             ' Save the file
  274.             Save_Click
  275.         Case vbCancel
  276.             ' Cancels the open
  277.             Exit Sub
  278.     End Select
  279. End If
  280. ' Opens Common dialog box
  281. FileNam = DialogFile(Form1, 1, "Open List", "", "TXT", App.Path, ".txt")
  282. ' Checks for valid name
  283. If Len(FileNam) = 0 Then Exit Sub
  284. ' Opens list
  285. OpenMyList (FileNam)
  286. ' Newly opened lists aren't "Dirty"
  287. Dirty = False
  288. End Sub
  289. Private Sub Save_Click()
  290. Dim FileNames As String, FF As Integer, Response As String, X As Integer
  291. ' Opens Common Dialog Box
  292. FileNames = DialogFile(Form1, 2, "Save List", "", "txt", App.Path, ".TXT")
  293. ' Checks for valid name
  294. If Len(FileNames) = 0 Then Exit Sub
  295. ' Gets file number
  296. FF = FreeFile
  297. ' Opens list
  298. Open FileNames For Output As #FF
  299.     For X = 0 To List1.ListCount - 1
  300.         ' Writes list
  301.         Print #FF, List1.List(X)
  302.     Next
  303. Close
  304. ' Saved lists aren't "Dirty"
  305. Dirty = False
  306. ' Adds saved file to MRU
  307. AddToMRUX (FileNames)
  308. End Sub
  309. Private Sub Text1_Change()
  310. ' When the text changes, select the matching items
  311. For X = 0 To (List1.ListCount - 1)
  312.     List1.Selected(X) = False
  313.     If Len(Text1.Text) <> 0 Then
  314.         If Text1.Text = Left(List1.List(X), Len(Text1.Text)) Then List1.Selected(X) = True
  315.     End If
  316. End Sub
  317.