Type of '<variablename>' cannot be inferred from an expression containing '<variablename>'
The compiler cannot infer the data type of a variable if the variable is used in establishing its initial value in the declaration.
For example, with Option Infer
set to On
, the following examples do not compile:
Declarations
' Does not compile with Option Infer on. Dim m = m Dim d = someFunction(d)
For
loop' Does not compile with Option Infer on. For j = 1 To j Next
For Each
loop' Does not compile with Option Infer on. For Each customer In customer.Orders Next
Error ID: BC30980
To correct this error
If the two variables were intended to refer to different values, change the name of the variable that you are declaring.
Use a literal value instead of the variable name in the initial value, on the right side of the assignment.
Use an
As
clause to specify the type of the variable you are declaring.
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for