Results 1 to 1 of 1

Thread: VB - add recent file list to menu

  1. #1

    Thread Starter
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    VB - add recent file list to menu

    on a form add a menu item (mnuOpen), a menu seperator (mnuSep) not set to visible, an array (1 To 4) of menu items (mnuRegFile) all not set to visible, a common dialoge control (CDlog), and a textbox (txtTest)

    VB Code:
    1. Option Explicit
    2. Dim i As Integer
    3. Dim temp As String
    4. Dim blnOnList As Boolean
    5.  
    6. Private Sub Form_Load()
    7.     For i = 1 To 4
    8.         mnuRegFile(i).Caption = GetSetting("MyProg", "filemenu", i, "")
    9.         If mnuRegFile(i).Caption <> "" Then mnuRegFile(i).Visible = True
    10.     Next
    11.  
    12.     If mnuRegFile(1).Visible = True Then mnuSep.Visible = True
    13. End Sub
    14.  
    15. Private Sub mnuOpen_Click()
    16.     Err.Clear
    17.     On Error GoTo ErrHandle
    18.     With CDlog
    19.         .FileName = ""
    20.         .Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
    21.         .ShowOpen
    22.     End With
    23.     Open CDlog.FileName For Input As #1
    24.     temp = Input(LOF(1), 1)
    25.     Close #1
    26.     txtTest.Text = temp
    27.    
    28.     AddRegList
    29.  
    30.     Exit Sub
    31.  
    32. ErrHandle:
    33.     Close #1
    34.     MsgBox Err.Description, vbCritical, "Open Error"
    35.  
    36. End Sub
    37.  
    38. Private Sub AddRegList()
    39.     For i = 1 To 4
    40.         mnuRegFile(i).Caption = GetSetting("MyProg", "filemenu", i, "")
    41.     Next
    42.    
    43.     blnOnList = False                           'check if its already
    44.     For i = 1 To 4
    45.         If CDlog.FileName = mnuRegFile(i).Caption Then
    46.             blnOnList = True
    47.             Exit For
    48.         End If
    49.     Next                                        'on the list
    50.    
    51.     If blnOnList = True And i < 4 Then
    52.         Select Case i
    53.             Case 2
    54.                 mnuRegFile(2).Caption = mnuRegFile(1).Caption
    55.                 mnuRegFile(1).Caption = CDlog.FileName
    56.             Case 3
    57.                 mnuRegFile(3).Caption = mnuRegFile(2).Caption
    58.                 mnuRegFile(2).Caption = mnuRegFile(1).Caption
    59.                 mnuRegFile(1).Caption = CDlog.FileName
    60.         End Select
    61.     Else
    62.         mnuRegFile(4).Caption = mnuRegFile(3).Caption
    63.         mnuRegFile(3).Caption = mnuRegFile(2).Caption
    64.         mnuRegFile(2).Caption = mnuRegFile(1).Caption
    65.         mnuRegFile(1).Caption = CDlog.FileName
    66.     End If
    67.    
    68.     mnuRegFile(1).Visible = True
    69.     mnuSep.Visible = True
    70.     For i = 2 To 4
    71.         If mnuRegFile(i).Caption <> "" Then mnuRegFile(i).Visible = True
    72.     Next i
    73.    
    74.     For i = 1 To 4
    75.         SaveSetting "MyProg", "filemenu", i, mnuRegFile(i).Caption
    76.     Next i
    77. End Sub
    78.  
    79. Private Sub mnuRegFile_Click(Index As Integer)
    80.     Err.Clear
    81.     On Error GoTo ErrHandle
    82.     CDlog.FileName = GetSetting("MyProg", "filemenu", Index, "")
    83.     Open CDlog.FileName For Input As #1
    84.     temp = Input(LOF(1), 1)
    85.     Close #1
    86.     txtTest.Text = temp
    87.    
    88.     AddRegList
    89.    
    90.     Exit Sub
    91.    
    92. ErrHandle:
    93.     Close #1
    94.     MsgBox Err.Description, vbCritical, "Error"
    95. End Sub
    Last edited by dis1411; Sep 28th, 2003 at 02:16 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width