This documentation is archived and is not being maintained.

Code: Displaying Variables in a String (Visual Basic)

Visual Studio .NET 2003

This example declares the variable number and then displays it and its square in the string result.


Private Sub DisplayTheSquare()
    Dim number As Integer = 4
    Dim result As String = _
        String.Format("{0} times {0} = {1}", _
        number, number * number)
End Sub

Compiling the Code

This example requires:

  • A reference to the System namespace.

Robust programming

The following conditions may create an exception:

See Also

String Manipulation | Strings | String.Format Method | System Input/Output Example Topics