i am using commondialog to open files in directory so i have question how would i save that directory the user access last time so when user use the program again it will open the same directory which was accessed last.
Printable View
i am using commondialog to open files in directory so i have question how would i save that directory the user access last time so when user use the program again it will open the same directory which was accessed last.
Take a look at this...
Dim int_I As Integer
dialog1.FileName = ""
dialog1.DialogTitle = "Select the file"
dialog1.DefaultExt = "Txt"
dialog1.Filter = "All (*.*)|*.*|Text (*.txt)|*.txt"
dialog1.InitDir = GetSetting("your app", "section", "setting", "default value")
dialog1.Action = 1
int_I = InStr(1, dialog1.FileName, dialog1.FileTitle)
If int_I > 0 And Len(Trim$(dialog1.FileName)) > 0 Then
SaveSetting "your app", "section", "setting", Left$(dialog1.FileName, int_I - 1)
End If
'interuped before I could finish but seeing as I did it
'I may as well post it..very similar to above except I use
'a variable
Code:Option Explicit
Public myStoredDirName As String
Private Sub Command1_Click()
On Error GoTo out:
CommonDialog1.CancelError = True
CommonDialog1.InitDir = myStoredDirName 'set dir path
CommonDialog1.CancelError = True 'used in cancel code
CommonDialog1.Filter = "All files(*.*)|*.*" 'filter for all files
CommonDialog1.ShowOpen 'show files
myStoredDirName = CommonDialog1.FileName
'open your file or whatever here
out:
'cancel was pressed
End Sub
Private Sub Form_Load()
'this will load it into the register
myStoredDirName = GetSetting("project1", "StringValue", "Value", 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
'this will save it into the register when you quit
SaveSetting "project1", "StringValue", "Value", myStoredDirName
End Sub