-
Private Sub Form_Load()
Dim stCurDir As String
Dim stIniFile As String
stIniFile = App.Path & "\list.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
It wont open the .ini to get the set directory...
Why?
-
Have you checked the value of stIniFile to make sure it's looking in the right place?
App.Path points to the location from which your project was launched, so if you opened your project from within VB, then the App.Path would point to your VB location, i.e. "C:\Program Files\Microsoft Visual Studio\VB98"
-
nope...in the right place...it just wont read the .ini file...is there another way to do it?
-
Have you traced the code to see what is happening? I copied your code and placed a list.ini file in the app.path and while I don't know what your list.ini file looks like, by tracing I was able see that the ini file is read.
-
You could always handle using else in your code whenever you use if to avoid errors:
Code:
Private Sub Form_Load()
Dim stCurDir As String
Dim stIniFile As String
stIniFile = App.Path & "\list.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)
Else
MsgBox "Stored Directory " & stCurDir & "not found"
End If
Else
MsgBox "INIFILE empty"
End If
Close #1
Else
MsgBox "INIFILE " & stIniFile & " not found"
End If
End Sub
-
I fixed it...
(If your free please check out my post titled Lawrence Jesterton)