Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening Photo folders in VB6 4

Status
Not open for further replies.

Dues

Technical User
Jul 22, 2014
9
US
I have a VB6 tst program that consists of a form with an image box on it.
The Load sub has :

fnum as free file()
Open App. Path & "\Photos" for input as fnum
etc

Photos is a picture folder that would be accesable by App.Path method, I thought.
But I get a File not found message
What am I doing wrong?

I would like to have the program open the Photo foulder, and be able to click on a picture
to assign it to the image box, permenently.

Any help would be appreciated.
 
You can't open a folder for input, so the Open statement is trying to treat that name as a file - which you don't have.

You can't change the program itself at runtime, so I'm not sure what you mean by "permanently.
 
Thank you for your responce.
The assigned picture will be associated with a person on a list.
By "permenently" I meant that the assigned picture will be shown whenever the person on the list is clicked.
A command button will save the assignments and other changes to a file.
I can take care of that coding.
Thanks again
 
Unless your pool of "photos" is fixed at installation you mgiht save yourself some grief and find another place for them now.

Program Files subfolders are protected against writing by standard users.
 
What photo container can I use that can be accessed by a the program ?
 
App.Path points to the 'default' location of your program, so initially it is somthing like "C:\Program Files (x86)\Microsoft Visual Studio\VB98"

But you can save your VB6 application in, let's say: "C:\MyFolder\MyPhotoApp" and App.Path will point to that location from your application. And that's where you may keep your photos.


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
App.Path provides you the actual path, not a "default" path - whatever that was meant to mean.

This works fine for read-only files put in place by your installer. Other locations you might choose would be based on the purpose of the files.

For per-machine files only operated upon by your programs you'd have your installer create a subfolder under ProgramData and set the required access on it to allow all-user writing if required. Per-user files go into a subfolder created under LocalAppData on first run by each user.

For files users must manipulate directly you have places such as Documents, Pictures, etc. and normally you let the user pick the location via dialogs. You might persist these kinds of locations as part of the user's "settings" in your program or they might require navigation each time... it depends on the application. But you shouldn't just dump program data in those locations without user direction.
 
Don't dump programs into random locations. Program Files is the preferred location for many reasons, and is protected to help prevent your program from becoming infected by malware injection or replacment.
 
Thank you Dilettante for your advice.
Actualy, my problem is that I can't seem tp get my teeth on the Photo foulder accessing method.
Suppose I make a new text program, call it Phottest. It will contain one form with a picture and/or image control on it and a Command button.
The program wiil on my C drive, which also contains a Photo folder. clicking the Command bottonw will access the photo folder thru the
App. Path method and opens the folder showing the pictures. Clicking on a picture places it in the picture box.
Will this work, or am I missing something?
This will be a teaching program and if you can show me the coding for it I'll be very greatful.
 
If your program only reads these files there is no problem with a Photo or Photos subfolder in the program Files folder.

Perhaps you are really just looking for the LoadPicture() method?
 
These forums are for professionals, so if you don't actually use VB6 professionally you really shouldn't be posting here.
 
Open new VB6 Project, on your Form place:
[ul]
[li]Picture1 (PictureBox),[/li]
[li]Image1 (Image),[/li]
[li]Command1 (CommandButton)[/li]
[li]and CommonDialog1 [/ul](how to find CommonDialog1)[/li]

Try this code:

Code:
Option Explicit

Private Sub Command1_Click()

With CommonDialog1
    .Filter = "Apps (*.jpg)|*.jpg|All files (*.*)|*.*"
    .DefaultExt = "jpg"
    .DialogTitle = "Select Picture File"
    .ShowOpen
    Picture1.Picture = LoadPicture(.FileName)
    Image1.Picture = LoadPicture(.FileName)
End With

End Sub

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Image1.picture=loadpicture(app.path k "/picturefoldername" & mypicture)

If you create a sub folder (picturefoldername) for your photos in the same folder you have your app then this will show the photo mypicture in your image box in the app.

To select different pictures first make mypicture = "new picture.jpg" or whatever

All Professionals are originally amateurs and usually learn quicker from other professionals.
 
Andy
Thanks a lot.
Your sggested program works fine, but, it opens to a file of picture names for the user to pick. Why can't it open the Photo file and show all the thumbnail photos that can be picked?

Dilitante
I signed up as a technical user. Is that not an aceptible catagory?
Though I'm not a profesianal programer I have written many useful prograns for myself and others.
You might say that I'm an auto-didact user of VB6, there are still areas where I can use help.
 
That all depends of how do you want your program to work.
This is just my guess here, but the way I envision it is: one person / user / admin will be in charge of assigning which pictures goes with which person, and this ‘admin’ would have the ability to use some kind of program I showed you. After admin is done, you would have some information in a table (every person will have a record with their picture):

[pre]
Person Photo
Bob W. BobW.jpg
Susie Q. SusieQ.jpg
John S. JohnS.jpg
John P. JohnP.jpg
[/pre]
And assuming all those photos reside in C:\SomeFolder\Photos\ folder

So if user selects Susie Q. from the list / drop-down combo, in the picture box you would show:

Picture1.Picture = LoadPicture(“C:\SomeFolder\Photos\SusieQ.jpg”)

But all the info would come from
Const strPATH As String = “C:\SomeFolder\Photos\”
And SusieQ.jpg would come from the table.

So your code would look something like:

Picture1.Picture = LoadPicture(strPATH & "SusieQ.jpg”)


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Why can't it open the Photo file and show all the thumbnail photos that can be picked?"

Let me rephrase your question:

"Why can't it open the Photo folder and show all the thumbnail photos from that folder/location that can be picked?"

Yes, you can.
You can place an array of PictureBoxes (or Image boxes) on your form. Number of elements in your array will be based on how many photo files you have in your folder.


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Andy
I'm having quite a "fun" time with this!
I have a form with your suggested coding except that I have an array of image boxes to recieve the pictures.
DD in an integer to use with a For Next operation to access the "Select Picture File" pictures.
But How? Can this work at all?

With CommonDialog1
.Filter = "Apps (*.jpg)|*.jpg|All files (*.*)|*.*"
.DefaultExt = "jpg"
.DialogTitle = "Select Picture File"
.ShowOpen
Image1(DD).Picture = LoadPicture(.FileName)
End With
 
I am afraid with all those different posts, approaches, and given solutions - now I’m lost with what you are trying to accomplish in your app. Could you re-state in plain English what you want to happen, please?

As far as having fun with displaying pictures in an array of Images, I know what you mean. Some time ago I wrote a program to display all pictures from any chosen location (folder): user pointed to a folder and I displayed all pictures in that folder in an array of Images (or PictureBoxes, don’t remember which one I used, but one of them has Stretch property). I placed an Image array on the ‘frame in the frame’ so I can adjust the height of one frame and be able to move it (slide it) up and down in another frame and show all pictures in chosen folder. That was fun.

Are you trying to do the same: display all available picture files on one Form from a certain folder?

Now to your question here:
“Can this work at all?” – Yes, but...
You need to have an array of Image1(0) (just an array of this 1 element / control with index of 0) on your Form to start with. This will allow you to show the very first picture chosen by the user. So when you run your code and DD increases to 1 (next picture), you need to load Image1(1) (notice here the index is 1) into your form at run time in order to use it to display a newly selected picture by user. So every time after the initial first time, you will increase the array on Image1 control by 1.


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Andy
Thanks for your responses to a guy whose had little experiance in this area of VB6. I appreciate it.
Let me describe my problem from skratch. I'm writing a program for a Sunday School class.
The program will have a write up form to enter details of each member. Along with this I would like it to be able to show a photo of the individual. The write up screen will have a Command button called "Photo"
The photos are in a folder callled "Photos" on the C: drive, (or else where), so that in writing up a new member the user can go to the folder from the write up screen by clicking on the "Photo" button. This will open up a form showing all the photos in thumbnail mode. Clicking on a photo will assign that photo to an existing image box on the write up screen and close the form showing the photos. All information and photo information is then saved to a file when a "Save Changes" Button is clicked.
When the program starts a list of all written individual's names appear in a list box. The user can clicks on an individual on the list and the write up screen of that individual apears along with his/her photo.
I can handle all the coding required except showing thumbnail photos and selecting one to place it on another image box. There are other programs that do this kind of thing, eg ancester programs.
This is a long winded explanation but I hope it clears things up.
Thanks again

 
How about this: instead of separate Form with pictures, what would you say about using a drop-down combo with pictures instead? :) So your user would just select their picture from that combo?

Here is some information of How To Use the ImageCombo Control with Visual Basic 6.0

There are some steps of how to do it in design time, but you can do the same at run time, too.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top