Home

VBA Data Types: String

 

Introduction

To declare a string variable, use the String data type. Here is an example:

Sub Exercise()
    Dim CountryName As String
End Sub

The type character for the String data type is $. Therefore, the above declaration could be written as:

Sub Exercise()
    Dim CountryName$
End Sub

As mentioned already, after declaring a variable, you can assign a value to it. The value of a string variable must be included inside of double-quotes. Here is an example:

Sub Exercise()
    Dim CountryName As String
    
    CountryName = "Brésil"
End Sub

To convert a value to a string, you can call the CStr() function:

CStr(Value To Convert to String)

In the parentheses of the CStr(), enter the value that you want to convert to string.

 
 
     
 

Home Copyright © 2009-2010 FunctionX, Inc.