Share via


SetFromString Method

Stores the String value into the Vector of bytes including the terminating null character. Value might be truncated unless Resizable is True. The string is stored as an ANSI string unless Unicode is True, in which case it is stored as a Unicode string.

Syntax

  object.SetFromString( _
    Value As String, _
    [Resizable As Boolean,] _
    [Unicode As Boolean])

Parameters

  • Value
    Required. String value.

  • Resizable
    Optional. Boolean value.

    • False
      Not resizable.
    • True
      Default. Resizable.
  • Unicode
    Optional. Boolean value.

    • False
      Not Unicode.
    • True
      Default. Unicode.

Remarks

Because vectors of bytes can actually be strings, this method provides a way to set the contents of a Vector of bytes from a String in either Unicode or ANSI form. Note that since all strings are Unicode in Microsoft Visual Basic, you need to specify which way you would like the string stored.

One common point of confusion is how to create a Vector of bytes. Many Visual Basic developers might be tempted to try the following:


'Do not follow this example
Dim v 'As Vector

Set v = CreateObject("WIA.Vector")

v.Add "A"

However, the previous example does not work as expected. It actually creates a Vector of strings where the first element contains the string "A". Instead, to create a Vector containing bytes you can use the SetFromString method or the CByte function in Visual Basic as follows:


Dim v 'As Vector
Dim b 'As Byte

Set v = CreateObject("WIA.Vector")

b = Asc("A")
v.Add CByte(b)

For example code, see Exif Filter: Write a New Title Tag to an Image.

Method Information

Minimum operating systems Windows XP SP1

See Also

Value (Property), Value (Rational), Add (Vector)