FileSystemObject (VB6)

I've been asked to modify my application (Be-Grudgedly) to insert a comment with an image file.
I've looked into this and feel the best way to go is with "FileSystemObject"

I've modified a click event with the image to firstly check if a text file exists with the same name as the image:
<pre>Private Function imgclick(i As Integer)
Dim fso As New FileSystemObject
Dim intIndex As Integer
Dim strFile As String
Dim j As Integer
For j = 1 To intNumberOfImages
If j = i Then
Me.PreviewImg.Picture = Me.Controls("img" & j).Picture

Re: FileSystemObject (VB6)

An alternative would be to maintain a single text file with the comments, or even a small Access database (the users don't need to have Access for this, your VB6 application can read and write Access databases.)

Re: FileSystemObject (VB6)

Dave,

The code between the two blue lines is just technical stuff. You could use an input box to let the user enter a comment, but why not use a text box on the form itself, with a command button to store the comment.

Re: FileSystemObject (VB6)

Hans
Each pic has a textbox anyway showing the path and file name.
To be honest, I dont really need to show the path information at all, if I could use these texts instead and use the original code as the first post above, this would be great.
It would also control the amount of clutter on screen also.

Is it possible to insert the comment ib the FileSystemObject ? and show the texts in these controls ?

Re: FileSystemObject (VB6)

The link to MSDN I posted in my first reply mentions the ReadLine and WriteLine method of the TextStream object. You can use these to retrieve and store text in a text file.

You probably populate the text boxes in the FillImages procedure. You could use ReadLine to get the comment from the text file corresponding to the image, then put it in the text box instead of the path.

Similarly, you can use WriteLine to store the comment from the text box into the text file.

Re: FileSystemObject (VB6)

Does this have to be done for free, or can you license a third party tool? JPG files have room in the header for comments, so it seems natural to just stuff them in there, but you would need some kind of JPG-format-aware control to do that. Of course, if you cannot change the files for legal reasons (preservation of evidence), then this would not be a good approach...

If you review the FileSystemObject documentation in more detail, you will find that it has a method to return the file name without its extension. HansV's code might be equally (or even more) reliable, but the FSO method probably is more self-documenting for the next person who has to edit this code. (I forget its name... self-documenting <> memorable. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> )

Re: FileSystemObject (VB6)

Just a thought, but as yo uare using VB you should have access to the RichText control. You could use this in place of a text box and just load the relevant text file into the control. You can edit the RichTextt control text and save it when appropriate.