Comment example for Visual Basic

Note: Also works with Access 95 and 97.

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 FilePath As String 'File to be updated
Dim i As Long 'Loop counter and array index
Dim RasterIO As New LEADRasterIO
Dim RasterProc As New LEADRasterProcess
Dim RasterVarEmpty As New LEADRasterVariant
Dim RasterVar As New LEADRasterVariant

'Specify the file that we will update. 
FilePath = "d:\temp\combined.mpt"
'Get all of the current comments from the file. 
'Temporarily disable method errors so that we do not fail when comments are missing. 
RasterIO.EnableMethodErrors = False
For i = 0 To CMNT_LAST
  RasterIO.Comment(i) = RasterVarEmpty
  RasterIO.Comment(i) = RasterIO.ReadComment(LEADRasterView1.Raster, FilePath, 1, i) 
Next i
'Load and modify the image. 
RasterIO.EnableMethodErrors = True
RasterIO.Load LEADRasterView1.Raster, FilePath, 0, 0, 1
RasterProc.Reverse LEADRasterView1.Raster
'Update the CMNT_SZDESC comment. 
MyCommentText = Chr(13) + "This image has been reversed." 
RasterVar.Type = VALUE_STRING
RasterVar = RasterIO.Comment(CMNT_SZDESC) 
RasterVar.StringValue = RasterVar.StringValue + MyCommentText
RasterIO.Comment(CMNT_SZDESC) = RasterVar
'Save the file and read the comment that we saved. 
RasterIO.Save LEADRasterView1.Raster, FilePath, FILE_TIF, LEADRasterView1.Raster.BitmapBits, 0, SAVE_OVERWRITE
RasterVar = RasterIO.ReadComment(LEADRasterView1.Raster, FilePath, 1, CMNT_SZDESC) 
'Display the message
MsgBox RasterVar.StringValue
'Clear the comments from memory
For i = 0 To CMNT_LAST
  RasterIO.Comment(i) = RasterVarEmpty
Next i