BC30068: Expression is a value and therefore cannot be the target of an assignment

A statement attempts to assign a value to an expression. You can assign a value only to a writable variable, property, or array element at run time. The following example illustrates how this error can occur.

Dim yesterday As Integer
ReadOnly maximum As Integer = 45
yesterday + 1 = DatePart(DateInterval.Day, Now)
' The preceding line is an ERROR because of an expression on the left.
maximum = 50
' The preceding line is an ERROR because maximum is declared ReadOnly.

Similar examples could apply to properties and array elements.

Indirect Access. Indirect access through a value type can also generate this error. Consider the following code example, which attempts to set the value of Point by accessing it indirectly through Location.

' Assume this code runs inside Form1.
Dim exitButton As New System.Windows.Forms.Button()
exitButton.Text = "Exit this form"
exitButton.Location.X = 140
' The preceding line is an ERROR because of no storage for Location.

The last statement of the preceding example fails because it creates only a temporary allocation for the Point structure returned by the Location property. A structure is a value type, and the temporary structure is not retained after the statement runs. The problem is resolved by declaring and using a variable for Location, which creates a more permanent allocation for the Point structure. The following example shows code that can replace the last statement of the preceding example.

Dim exitLocation as New System.Drawing.Point(140, exitButton.Location.Y)
exitButton.Location = exitLocation

Error ID: BC30068

To correct this error

  • If the statement assigns a value to an expression, replace the expression with a single writable variable, property, or array element.

  • If the statement makes indirect access through a value type (usually a structure), create a variable to hold the value type.

  • Assign the appropriate structure (or other value type) to the variable.

  • Use the variable to access the property to assign it a value.

See also