INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Opening Photo folders in VB6

Opening Photo folders in VB6

(OP)
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.

RE: Opening Photo folders in VB6

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."

RE: Opening Photo folders in VB6

(OP)
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

RE: Opening Photo folders in VB6

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.

RE: Opening Photo folders in VB6

(OP)
What photo container can I use that can be accessed by a the program ?

RE: Opening Photo folders in VB6

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.

RE: Opening Photo folders in VB6

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.

RE: Opening Photo folders in VB6

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.

RE: Opening Photo folders in VB6

(OP)
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.

RE: Opening Photo folders in VB6

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?

RE: Opening Photo folders in VB6

These forums are for professionals, so if you don't actually use VB6 professionally you really shouldn't be posting here.

RE: Opening Photo folders in VB6

Open new VB6 Project, on your Form place:
  • Picture1 (PictureBox),
  • Image1 (Image),
  • Command1 (CommandButton)
  • and CommonDialog1
(how to find CommonDialog1)

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.

RE: Opening Photo folders in VB6

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.

RE: Opening Photo folders in VB6

(OP)
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.

RE: Opening Photo folders in VB6

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):

Person        Photo
Bob W.       BobW.jpg
Susie Q.   SusieQ.jpg
John S.     JohnS.jpg
John P.     JohnP.jpg
 
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.

RE: Opening Photo folders in VB6

"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.

RE: Opening Photo folders in VB6

(OP)
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

RE: Opening Photo folders in VB6

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.

RE: Opening Photo folders in VB6

(OP)
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

RE: Opening Photo folders in VB6

How about this: instead of separate Form with pictures, what would you say about using a drop-down combo with pictures instead? smile 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.

RE: Opening Photo folders in VB6

Here is another idea of what picture goes with what person:
Let’s say you are in charge of taking / collecting / storing / naming the pictures (files). If you would name the jpg file SusieQBrown.jpg for a person Susie Q. Brown, as soon as Susie would filled up her name in appropriate places (text boxes) on the form, you would just show the picture of her in the image box. No selection / arrays / image combos needed. Just magic. And you avoid selecting the wrong picture for that person because no selection is made by the person. Let computer do this job.

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.

RE: Opening Photo folders in VB6

here's something that illustrates one way of meeting your basic requirements:

You will need a VB6 project with two forms. On the first form place an Image control and a Command button captioned 'Photo'. Then paste in the following complex bit of code:

CODE

Option Explicit

Private Sub Command1_Click()
    Form2.Show
End Sub 

Ok, now we get complicated. We need to:

1) Add the Microsoft Internet Controls component; and
2) Add a reference to 'Microsoft Shell Controls and Automation'

Now put a webbrowser control on Form2. Then paste in the following code into Form2:

CODE

Option Explicit

Dim WithEvents shfolder As ShellFolderView

Public Enum FolderViewMode
    FVM_ICON = 1
    FVM_SMALLICON = 2
    FVM_LIST = 3
    fvm_details = 4
    FVM_THUMBNAIL = 5
    FVM_TILE = 6
    FVM_THUMBSTRIP = 7
End Enum

' Just for this example. You'd need to set this as appropriate for your environment
Private Const PictureFolderURL = "file:\\C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures"

Private Sub Form_Load()
    WebBrowser1.Navigate PictureFolderURL
    WebBrowser1.Document.CurrentViewMode = FVM_THUMBNAIL
    Set shfolder = WebBrowser1.Document 'add interface to start tracking events for this document
    WebBrowser1.Move 0, 0, Form2.ScaleWidth, Form2.ScaleHeight
End Sub

Private Sub Form_Resize()
    WebBrowser1.Move 0, 0, Form2.ScaleWidth, Form2.ScaleHeight
End Sub

Private Function shfolder_DefaultVerbInvoked() As Boolean
    sh_DefaultVerbInvoked = False ' disable default action for doubleclick
End Function

Private Sub shfolder_SelectionChanged()
    'shfolder.SelectItem shfolder.FocusedItem, 1 + 4 ' Select and highlight, but not needed for this example
    GetPhoto
End Sub

Private Function shfolder_VerbInvoked() As Boolean
    MsgBox "Popup menu items are disabled"
    shfolder_VerbInvoked=False
End Function

Public Sub GetPhoto()
    Form1.Image1 = LoadPicture(shfolder.FocusedItem.Path)
    Form1.Image1.ToolTipText = shfolder.FocusedItem.Path
    Unload Me
End Sub 

And that's it. This basically does exactly what you described in your post of 4 Aug 14 13:50
It is just example code, not bulletproof - but illustrates how we can leverage already existing functionality for our own use with fairly minimal effort.

RE: Opening Photo folders in VB6

I like this answer (GetPhoto doesn't need to be Public above), however I had the idea that this can fail beginning with Windows 7 which often substitutes an undocumented "item view" control for the SysListView32 Common Control you normally get.

Probably doesn't matter if ShellFolderView's members expose enough functionality though. I have some programs myself that have to subclass the SysListView32 window inside ShellFolderView to do some fancier stuff.

RE: Opening Photo folders in VB6

(OP)
Thank you strongm and dilitante,
last night I hit on a way that I think can make this work. Using a DriveListBox and Directorylistbox, I can access and open the Photo folder.
I'll work on it.

RE: Opening Photo folders in VB6

Is there really an issue with the use of the CommonDialog.ShowOpen?

If needed the user can change the view of the folder to show thumbnails. I believe on most supported versions of Windows it will "remember" the selected view for subsequent usages of a particular folder.

Or is it another issue? Maybe you need to have more control so the user can't navigate away to subfolders or some other folder?

RE: Opening Photo folders in VB6

(OP)
OK Andy and dilettante
I havea a program with 1 Form and the following code:

Option Explicit
Dim DD As Integer, Pict As String, fnum As Integer

Private Sub Command1_Click() 'End
Unload Form1
End
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
File1.Visible = True
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Command3_Click()
On Error Resume Next
For DD = 0 To File1.ListCount - 1
Pict = Dir1 & "\" & File1.List(DD)
Image1(DD).Picture = LoadPicture(Pict)
Next
End Sub

Private Sub Image1_Click(Index As Integer)
On Error Resume Next
Pict = Dir1 & "\" & File1.List(Index)
Image2.Picture = LoadPicture(Pict)
End Sub

The Form has a DriveListBox, DirectoryListBox, Get Photo Button,FileListBox, an array of Image1(0 to 9) boxes, a larger Image2 box and an "End" button. When one Clicks on one of the small Image1 picture, that picture is assigned to Image2 which will be recorded.
The Photos folder is in the program VB6 folder.
The program works as I intended, but perhaps you may suggest some improvments.
To start the program, the user has to double click "Photos" in the list box. Can this step be eliminated so that double clicking "Photos" is done automaticlly when the program starts?

This is only a test program, I will later add means to record and save the information so that a user can click on a name in the FileListBox amd that person's information and foto shown.
Thank you for any help

RE: Opening Photo folders in VB6

Quick question - why use the DriveListBox, DirectoryListBox, and FileListBox controls in preference to dilettante's advised use of the CommonDialog?

Those controls are a legacy from a time when the CommonDialog control did not exist. Is it, as he suggests, perhaps because you want to restrict what the users can do?

RE: Opening Photo folders in VB6

CommonDialog was actually my idea. Along with naming the photo files corresponding to people’s full names (no selection by user needed), and the use of ImageCombo control which should do exactly what Dues needs. Most of those ideas were ignored and not even responded to sad

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.

RE: Opening Photo folders in VB6

Yes, sorry. Wrongly credited.

>the use of ImageCombo control which should do exactly what Dues needs

Hmm. Not convinced, I'm afraid. I'd suggest that the ListView would be a better control for this, and better meet the described requirement. In either case you've got some work to do to make the images all appear as similarly sized thumbnails, since I think it is safe to assume that the source photos may be a) of differing sizes; and b) larger than a typical thumbnail.


RE: Opening Photo folders in VB6

The VB OCX ListView wrappers have some annoying quirks, in both versions 5 and 6.

When used in icon view with .LabelWrap = True long label values (ListItem.Text) can result in item arrangement problems. Just cosmetic but a nuisance nonetheless.

As your code "fills" the ListView, items will be added in a grid fashion as expected but a wrapped long label value seems to cause "gaps" in the grid arrangement. Everything snaps back "correctly" if you either resize the ListView control by any amount or if you set .Arrange = lvwNone then back to lvwAutoTop or lvwAutoLeft (which makes everything "jump" a little). Calling .Refresh, etc. don't do the job.

This is more disconcerting to the user than it might sound.

Adding items via API calls doesn't have this problem but leaves many OCX control properties out of sync with the underlying SysListView32 control.

RE: Opening Photo folders in VB6

Hence my solution, which avoids this nonsense winky smile (mind you, it has its own quirks ...)

RE: Opening Photo folders in VB6

One annoying feature of Commomdialog is it normally won't open showing the thumbnails by default
Perhaps a more experienced person may know how to use an API or method to do this?
Then it should satisfy the questioner I would think.

RE: Opening Photo folders in VB6

Quote:

CommonDialog was actually my idea. Along with naming the photo files corresponding to people’s full names (no selection by user needed)

From this and other posts, it seems that there is no need for any selection process at all. If you can use a fixed path and name the image files to match the people's names, then any kind of selection by the user can be made redundant.

For example, if the name is entered into Text1, and clicking Command1 loads the picture into Picture1, then you can simply do this:

CODE

Private Sub Command1_Click()
    Dim sFile As String
    Dim lLen As Long
    sFile = "C:\Photos\" & Text1.Text & ".jpg"
    On Error Resume Next
    lLen = FileLen(sFile)
    If Err Then
        Picture1.Picture = Nothing
    Else
        Picture1.Picture = LoadPicture(sFile)
    End If
    On Error Goto 0
End Sub 

In other words, don't over complicate things unless you have to. Use the KISS approach whenever you can.

Heaven doesn't want me, and Hell's afraid I'll take over!

RE: Opening Photo folders in VB6

It seems odd that there'd be some fixed folder, considering these are sort of "ID photos." They would need to be brought in from a camera or removable media or... well someplace.

Why not just support drag and drop to let the user drag from an Explorer window into the application?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close