-
I have a program that allows a user to navigate through folders to get to the files they are looking for...this program displays/plays the files, how can I save the directory they leave in? like once they quit the program, the current directory is the one that will be open next time they load the program...
-
Code:
Option Explicit
Private Sub Form_Load()
Dim stCurDir As String
Dim stIniFile As String
stIniFile = App.Path & "\myIni.Ini"
'make sure the file exists
If Dir$(stIniFile) <> "" Then
Open stIniFile For Input As #1
Line Input #1, stCurDir
ChDir (stCurDir)
Close #1
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim stIniFile As String
stIniFile = App.Path & "\myIni.Ini"
Open stIniFile For Output As #1
Print #1, CurDir
Close #1
End Sub
-
input past end of file......error...
-
nevermind...hah
-
-
Do I post it in a module, cause its not writing to the ini file...
-
there, got it...it was being a *****
-
Works fine on mine.
This new and improved code should cut out most errors.
Code:
Option Explicit
Private Sub Form_Load()
Dim stCurDir As String
Dim stIniFile As String
stIniFile = App.Path & "\myIni.Ini"
'make sure the file exists
If Dir$(stIniFile) <> "" Then
Open stIniFile For Input As #1
Line Input #1, stCurDir
If Trim$(stCurDir) <> "" Then
If Dir$(stCurDir, vbDirectory) <> "" Then
ChDir (stCurDir)
End If
End If
Close #1
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim stIniFile As String
stIniFile = App.Path & "\myIni.Ini"
Open stIniFile For Output As #1
Print #1, CurDir
Close #1
End Sub
I think you can probaly use some API like get setting etc, but i don't know how.
-
it made the list, but made the wrong directory...
-
does the form unload getting read? do i need to have it any place special...?
-
It keeps writing the directory the program is currently in...
-
-
I have a file that will access .ini files and code into them, you could just save it in a single file, or you could save it in the registry. then just put code in to open the file/reg.