DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Visual Basic 6 App.s in need of a way to list recent files used, ideas? Windows  (Read 8,494 times)

OptimalDesigns

  • (retired) Mathematical Engineer
  • Supporting Member
  • Joined in 2018
  • **
  • Posts: 70
An internet search came up with the following code.  How to use/implement it or use another way?
Also need more than 4 files saved as recent.  How to increase this to 'n' files?
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
« Last Edit: April 22, 2023, 03:32 PM by OptimalDesigns »

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • Participated in NANY Challenge Four Times
    • Coding Snacks
Recent File List tipps for VB6.
From way of coding, you either having a fixed numbered menu list what you fill at runtime or an endless long one by having a method that adds menu items with content.

OptimalDesigns

  • (retired) Mathematical Engineer
  • Supporting Member
  • Joined in 2018
  • **
  • Posts: 70
Recent File List tipps for VB6.
From way of coding, you either having a fixed numbered menu list what you fill at runtime or an endless long one by having a method that adds menu items with content.

Sorry you lost me ... i'm a math engineer trying to add a user's recent file names in order to make it simple to re-use them.

Original address: https://www.donationcoder.com/forum/index.php?topic=53363.0