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:
Option Explicit Dim i As Integer Dim temp As String Dim blnOnList As Boolean Private Sub Form_Load() For i = 1 To 4 mnuRegFile(i).Caption = GetSetting("MyProg", "filemenu", i, "") If mnuRegFile(i).Caption <> "" Then mnuRegFile(i).Visible = True Next If mnuRegFile(1).Visible = True Then mnuSep.Visible = True End Sub Private Sub mnuOpen_Click() Err.Clear On Error GoTo ErrHandle With CDlog .FileName = "" .Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly .ShowOpen End With Open CDlog.FileName For Input As #1 temp = Input(LOF(1), 1) Close #1 txtTest.Text = temp AddRegList Exit Sub ErrHandle: Close #1 MsgBox Err.Description, vbCritical, "Open Error" End Sub Private Sub AddRegList() For i = 1 To 4 mnuRegFile(i).Caption = GetSetting("MyProg", "filemenu", i, "") Next blnOnList = False 'check if its already For i = 1 To 4 If CDlog.FileName = mnuRegFile(i).Caption Then blnOnList = True Exit For End If Next 'on the list If blnOnList = True And i < 4 Then Select Case i Case 2 mnuRegFile(2).Caption = mnuRegFile(1).Caption mnuRegFile(1).Caption = CDlog.FileName Case 3 mnuRegFile(3).Caption = mnuRegFile(2).Caption mnuRegFile(2).Caption = mnuRegFile(1).Caption mnuRegFile(1).Caption = CDlog.FileName End Select Else mnuRegFile(4).Caption = mnuRegFile(3).Caption mnuRegFile(3).Caption = mnuRegFile(2).Caption mnuRegFile(2).Caption = mnuRegFile(1).Caption mnuRegFile(1).Caption = CDlog.FileName End If mnuRegFile(1).Visible = True mnuSep.Visible = True For i = 2 To 4 If mnuRegFile(i).Caption <> "" Then mnuRegFile(i).Visible = True Next i For i = 1 To 4 SaveSetting "MyProg", "filemenu", i, mnuRegFile(i).Caption Next i End Sub Private Sub mnuRegFile_Click(Index As Integer) Err.Clear On Error GoTo ErrHandle CDlog.FileName = GetSetting("MyProg", "filemenu", Index, "") Open CDlog.FileName For Input As #1 temp = Input(LOF(1), 1) Close #1 txtTest.Text = temp AddRegList Exit Sub ErrHandle: Close #1 MsgBox Err.Description, vbCritical, "Error" End Sub


Reply With Quote