Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Add recent file list to menu
View previous topic :: View next topic  
Author Message
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Oct 8th, 2003 06:05 AM    Post subject: Add recent file list to menu Reply with quote

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)

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
narf
Newbie


Joined: 13 Jan 2004
Posts: 2

PostPosted: Jan 17th, 2004 06:02 PM    Post subject: Reply with quote

being a beginner in V.B. and studing through corrospondance its nice to see code I can at least read. Can't make head or tail of my tutors code.

thanx


Thanx for the reply but if i had looked further into the code. I would have seen the forest behind the trees

Thanx again
_________________
Pinky. The brains behind the brain


Last edited by narf on Jan 24th, 2004 07:43 AM; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic