JFRobishow
Technical User
Hi everyone,
I'm working on a small application at the same time as I teach myself VB 6. I'm trying right now to fix a new error that occured today and while I think I identified the source of the error I can't fix it.
I'm populating a combobox using a text file with this procedure -->
It correctly find the file named "fileInput.txt" in the folder "ressources" which is in the project directory.
That always worked until today...
I tried adding a common control to the form so that the user could browse to a file, select it and the path would be added in a text area...here's my code :
The problem I have is after I select a file using the Common Control and close the form and open it again (it's the 2nd form the first one just open the 2nd form), I get a "Path not Found" in FillComboBox...I assume it can't find the path : ressources\fileInput.txt
If I close the whole application and re-open it it work again until I use the Common Control again.
I've been testing playing with it for a while and so far I'm thinking that when I use the Common Control and select a file it change the working directory to where the selected file is. I've tested this by copying the folder "ressources" to my E:\ drive, I then used the Common Control to select a file that was directly on E:
Sure enough it continued working since E:\ressources\fileInput.txt existed
If I remove the folder "ressources" and try again it's not working I get a "Path not Found" again.
I've tried in various location on the hard drive, continued getting error and finally I selected the project directory again and it started working...so from my test, it's changing the working directory.
Wheew, well that was a long post...I just wanted to show that I actually tried fixing the problem before running for help
Well now I think I've found the cause of the problem...as for the solution well I have no idea.
Is it possible to keep use a common control to select a file while still using virtual path to files the application use or will I have to use a full physical path to fileInput.txt?
I'm working on a small application at the same time as I teach myself VB 6. I'm trying right now to fix a new error that occured today and while I think I identified the source of the error I can't fix it.
I'm populating a combobox using a text file with this procedure -->
Code:
Private Sub FillComboBox()
Dim currentLine As String
Dim intFreeFile As Integer
intFreeFile = FreeFile
On Error GoTo ErrorFillComboBox
Open "ressources\fileInput.txt" For Input As intFreeFile
Do Until EOF(intFreeFile)
Line Input #intFreeFile, currentLine
sortedList.AddItem currentLine
Loop
'Close the file
Close #intFreeFile
'Add each item of the list in the combo box.
For i = 0 To sortedList.ListCount
comboFromFile.AddItem sortedList.List(i)
Next
Exit Sub
ErrorFillComboBox:
MsgBox Err & ":Error in FillComboBox. Error Message: " & Err.Description, vbCritical, "Warning"
Exit Sub
End Sub
It correctly find the file named "fileInput.txt" in the folder "ressources" which is in the project directory.
That always worked until today...
I tried adding a common control to the form so that the user could browse to a file, select it and the path would be added in a text area...here's my code :
Code:
Private Sub buttonBrowse1_Click()
FileOpenDlg.ShowOpen
textPath1.Text = FileOpenDlg.FileName
End Sub
The problem I have is after I select a file using the Common Control and close the form and open it again (it's the 2nd form the first one just open the 2nd form), I get a "Path not Found" in FillComboBox...I assume it can't find the path : ressources\fileInput.txt
If I close the whole application and re-open it it work again until I use the Common Control again.
I've been testing playing with it for a while and so far I'm thinking that when I use the Common Control and select a file it change the working directory to where the selected file is. I've tested this by copying the folder "ressources" to my E:\ drive, I then used the Common Control to select a file that was directly on E:
Sure enough it continued working since E:\ressources\fileInput.txt existed
If I remove the folder "ressources" and try again it's not working I get a "Path not Found" again.
I've tried in various location on the hard drive, continued getting error and finally I selected the project directory again and it started working...so from my test, it's changing the working directory.
Wheew, well that was a long post...I just wanted to show that I actually tried fixing the problem before running for help
Well now I think I've found the cause of the problem...as for the solution well I have no idea.
Is it possible to keep use a common control to select a file while still using virtual path to files the application use or will I have to use a full physical path to fileInput.txt?