SetTag example for Visual Basic
'Declare a FormLevel RasterIO object
Public WithEvents RasterIO As LEADRasterIO
Private Sub Form_Load()
Set RasterIO = New LEADRasterIO
End Sub
Private Sub SetAndRead_Click()
Dim myArray(4) As Long
Dim RasterVar As New LEADRasterVariant
' initialize the array
myArray(0) = 1
myArray(1) = 2
myArray(2) = 3
myArray(3) = 127
RasterVar.Type = VALUE_STRING
RasterVar.StringValue = "My text string"
' set a tag using one of the following:
RasterIO.SetTag 32768, TAG_ASCII, 0, RasterVar
' RasterIO.SetTag 32768, TAG_BYTE, 4, myArray
' RasterIO.SetTag 32768, TAG_DOUBLE, 4, myArray
' RasterIO.SetTag 32768, TAG_FLOAT, 4, myArray
' RasterIO.SetTag 32768, TAG_LONG, 4, myArray
' RasterIO.SetTag 32768, TAG_RATIONAL, 2, myArray
' RasterIO.SetTag 32768, TAG_SBYTE, 4, myArray
' RasterIO.SetTag 32768, TAG_SHORT, 4, myArray
' RasterIO.SetTag 32768, TAG_SLONG, 4, myArray
' RasterIO.SetTag 32768, TAG_SRATIONAL, 2, myArray
' RasterIO.SetTag 32768, TAG_SSHORT, 4, myArray
' RasterIO.SetTag 32768, TAG_UNDEFINED, 4, myArray
' Write the tag
RasterIO.WriteTag "d:\temp\test.tif", 1
Call ReadTag_Click
End Sub
Private Sub ReadTag_Click()
' read the tag back
RasterIO.ReadTag "d:\temp\test.tif", 1, 32768
Call GetAndDisplayTag(0)
End Sub
' This sub will get a certain tag and display it according to the tag type.
Private Sub GetAndDisplayTag(lTag As Long)
Dim myVar As Variant
Dim RasterVar As New LEADRasterVariant
Dim Msg$
Dim i As Long
Dim count As Long
Set RasterVar = RasterIO.GetTagData(lTag)
count = RasterIO.GetTagCount(lTag)
Msg$ = "Type = " + CStr(RasterIO.GetTagType(lTag))
Msg$ = Msg$ + Chr$(10) + Chr$(13) + "count = " + CStr(count)
If RasterIO.GetTagType(lTag) = TAG_ASCII Then
Msg$ = Msg$ + Chr$(10) + Chr$(13) + "Data = " + RasterVar.StringValue
ElseIf RasterIO.GetTagType(lTag) = TAG_RATIONAL Or _
RasterIO.GetTagType(lTag) = TAG_SRATIONAL Then
For i = 0 To count - 1
Msg$ = Msg$ + Chr$(10) + Chr$(13) + "Data(" + CStr(i) + ") = " + _
CStr(RasterVar.ShortItemValue(i * 2)) + "/" + CStr(RasterVar.ShortItemValue(i * 2 + 1))
Next i
Else
For i = 0 To count - 1
Msg$ = Msg$ + Chr$(10) + Chr$(13) + "Data(" + CStr(i) + ") = " + _
CStr(RasterVar.ShortItemValue(i))
Next
End If
MsgBox Msg$
End Sub