Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Code: Finding the Names of Resources in an Assembly (Visual Basic)
Code: Listing the Colors in the Color Structure (Visual Basic)
Code: Retrieving an Image that Is an Embedded Resource (Visual Basic)
Code: Running a Program (Visual Basic)
Code: Running a Program Associated with a File Type (Visual Basic)
Code: Sending an E-Mail Message (Visual Basic)
Expand Minimize

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.

Example

Private Sub DisplayTheSquare()
    Dim number As Integer = 4
    Dim result As String = _
        String.Format("{0} times {0} = {1}", _
        number, number * number)
    MsgBox(result)
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

Show:
© 2015 Microsoft