Comment example for Visual Basic

This example does the following:

1. Loads an image from a TIFF file.

2. Updates the current comment array by reading comments from the file.

3. Modifies one of the comments.

4. Modifies and saves the file.

5. Reads the comment that was saved, and displays it in a message box.

This example handles only string comments. For more complex comments, refer to Exif examples.

Dim MyCommentText As String 'String for CMNT_SZDESC
Dim NewCommentText As String 'String for CMNT_SZDESC that we read
Dim FilePath As String 'File to be updated
Dim i As Long 'Loop counter and array index

'Specify the file that we will update.
FilePath = "d:\lead\images\testcmt.tif"

'Get all of the current comments from the file.
'Temporarily disable method errors so that we do not fail when comments are missing.
Lead1.EnableMethodErrors = False
For i = 0 To CMNT_LAST
  Lead1.Comment(i) = Empty
  Lead1.Comment(i) = Lead1.ReadComment(FilePath, 0, i)
Next i
Lead1.EnableMethodErrors = True

'Load and modify the image.
Lead1.Load FilePath, 0, 0, 1
Lead1.Reverse

'Update the CMNT_SZDESC comment.
MyCommentText = Chr(13) + "This image has been reversed."
Lead1.Comment(CMNT_SZDESC) = Lead1.Comment(CMNT_SZDESC) + MyCommentText

'Save the file and read the comment that we saved.
Lead1.Save FilePath, FILE_TIF, Lead1.BitmapBits, 0, SAVE_OVERWRITE
NewCommentText = Lead1.ReadComment(FilePath, 0, CMNT_SZDESC)

'Display the message
MsgBox NewCommentText

'Clear the comments from memory
For i = 0 To CMNT_LAST
  Lead1.Comment(i) = Empty
Next i