String

You can use a string data type to store a sequence of characters. A string can contain any combination of letters, numbers, punctuation marks, and spaces. In order for VBA to recognize the start and stop of your string you must enclose it in quotes, for example:

SampleString = "This is a sample"

You can declare strings in one of two different types: variable length and fixed length. As the names state, you declare fixed-length strings with a maximum number of characters, and variable-length strings with as many as 2 billion characters.

To declare a fixed-length string, you need to specify the string length as part of the definition. When you declare a string length, the string is always that size, even if you assign a smaller string to it. For example, you declare a string of 25 characters as follows:

Dim FixedString As String * 25

Variable-length strings have no length specified:

Dim VarString As String

0 0

Post a comment