I'm trying to make a Browse Button in my VB6 project so that a window pops up asking people to find a pic on their computer, which will then be loaded into a picture box and resized. I got the resizing part working but the problem I'm running into is this: when I run my program, hit the Browse Button, select an image from my Pictures folder in My Docs, and click ok, it makes my program think it's in the "Pictures" folder and everything fails at the same time.
Here's my code:
CommonDialog1.ShowOpen
'The following lines just let me know that I now have a file patch to work with so I can load the picture with the picturebox
If IsNull(CommonDialog1.FileName) Then
Else
MsgBox "File selected is " & CommonDialog1.FileName
End If
The program seems to run great the first time, with the message "File selected is (actual_filename_and_path)" displayed after I choose a file, and gets no errors, but as soon as I shut it off and run it again, all the databases that I have in the same folder as the program (MS Access Databases) start complaining that they aren't found and the pictures in the relative path of \pics\*.jpg of my program also can't be found. I copied one of the databases (an .mdb file) from the program's folder where it's supposed to be to the "Pictures" folder in my Docs (The folder that I chose the image in while working with my browse button) and it found the database. Even in development mode (not in runtime) the properties box doesn't recognize a database in the same folder as the program anymore unless I put the file into the "Pictures" folder. Why does the program think it's in whatever folder I choose with the browse button and how do I fix this? My only way to get my program running again is to use an older version of the program that I have saved in a different folder that doesn't have a browse button (it's a very recent version so I didn't loose any of my work).
Actually, if I close VB and don't save, I can open the project up again and it will run without the Browse Button just fine. I had to revert to an earlier project once because to test what would happen, I changed the code to what I mentioned above and saved to see what would happen. It ran once, failed the second time, and when I closed and reopened VB it wouldn't run anymore...
Question
HellSpawn
I'm trying to make a Browse Button in my VB6 project so that a window pops up asking people to find a pic on their computer, which will then be loaded into a picture box and resized. I got the resizing part working but the problem I'm running into is this: when I run my program, hit the Browse Button, select an image from my Pictures folder in My Docs, and click ok, it makes my program think it's in the "Pictures" folder and everything fails at the same time.
Here's my code:
The program seems to run great the first time, with the message "File selected is (actual_filename_and_path)" displayed after I choose a file, and gets no errors, but as soon as I shut it off and run it again, all the databases that I have in the same folder as the program (MS Access Databases) start complaining that they aren't found and the pictures in the relative path of \pics\*.jpg of my program also can't be found. I copied one of the databases (an .mdb file) from the program's folder where it's supposed to be to the "Pictures" folder in my Docs (The folder that I chose the image in while working with my browse button) and it found the database. Even in development mode (not in runtime) the properties box doesn't recognize a database in the same folder as the program anymore unless I put the file into the "Pictures" folder. Why does the program think it's in whatever folder I choose with the browse button and how do I fix this? My only way to get my program running again is to use an older version of the program that I have saved in a different folder that doesn't have a browse button (it's a very recent version so I didn't loose any of my work).
Actually, if I close VB and don't save, I can open the project up again and it will run without the Browse Button just fine. I had to revert to an earlier project once because to test what would happen, I changed the code to what I mentioned above and saved to see what would happen. It ran once, failed the second time, and when I closed and reopened VB it wouldn't run anymore...
Edited by HellSpawnLink to comment
https://www.neowin.net/forum/topic/636159-vb6-browse-button-common-dialog-error/Share on other sites
7 answers to this question
Recommended Posts