hankknight
asked on
ASP.NET / VB: Compiler Error Message: BC30068: Expression is a value and therefore cannot be the target of an assignment.
Compiler Error Message: BC30068: Expression is a value and therefore cannot be the target of an assignment.
<%@ Page Language="VB" AutoEventWireup="false" %>
<%
Dim array(,) As Object = { _
{"ak","Alaska"}, _
{"al","Alabama"}, _
{"ca","California"} _
}
Dim Xyz As String = "Lakes in ak are cold cold but it is always hot in AL and can be hot or cold in ca"
Response.Write(xyz)
' Should say:
' Lakes in Alaska are cold cold but it is always hot in Alabama and can be hot or cold in California
%>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please ignore that last comment, moment of temporary insanity, just looking at it now :)
What line does the compiler complain about?
ASKER
If you test the code I posted you can see the error for yourself. Here it is:
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30068: Expression is a value and therefore cannot be the target of an assignment.
Source Error:
Line 10: Dim Xyz As String = "Lakes in ak are cold cold but it is always hot in AL and can be hot or cold in ca"
Line 11:
Line 12: For Each (states as string in state.Keys)
Line 13: xyz = xyz.Replace(" " & state & " ", " " & states(state) & " ")
Line 14: Next
Source File: C:\Websites\cms\sss.aspx Line: 12
Show Detailed Compiler Output:
¿c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\vbc.exe" /t:library /utf8output /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\40bc818c\1509f09d\App_Code.acesqnas.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Deployment\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Deployment.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\40bc818c\1509f09d\App_WebReferences.w-0_xvmb.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\40bc818c\1509f09d\App_global.asax.jnl0fduh.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /out:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\40bc818c\1509f09d\App_Web_fosvlg3e.dll" /debug- /nowarn:41008 /define:_MYTYPE=\"Web\" /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Collections.Specialized,System.ComponentModel.DataAnnotations,System.Configuration,System.Linq,System.Text,System.Text.RegularExpressions,System.Web,System.Web.Caching,System.Web.DynamicData,System.Web.SessionState,System.Web.Security,System.Web.Profile,System.Web.UI,System.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,System.Web.UI.HtmlControls,System.Xml.Linq /warnaserror- /optionInfer+ "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\40bc818c\1509f09d\App_Web_fosvlg3e.0.vb" "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\40bc818c\1509f09d\App_Web_fosvlg3e.1.vb"
Microsoft (R) Visual Basic Compiler version 10.0.30319.225
Copyright (c) Microsoft Corporation. All rights reserved.
C:\Websites\cms\sss.aspx(12) : error BC30068: Expression is a value and therefore cannot be the target of an assignment.
For Each (states as string in state.Keys)
~~~~~~~
C:\Websites\cms\sss.aspx(12) : error BC30198: ')' expected.
For Each (states as string in state.Keys)
~~
C:\Websites\cms\sss.aspx(12) : error BC30451: 'state' is not declared. It may be inaccessible due to its protection level.
For Each (states as string in state.Keys)
~~~~~
try this:
Dim array(,) As Object
ReDim array(3,3) As String = { _
{"ak","Alaska"}, _
{"al","Alabama"}, _
{"ca","California"} _
}
Dim array(,) As Object
ReDim array(3,3) As String = { _
{"ak","Alaska"}, _
{"al","Alabama"}, _
{"ca","California"} _
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
where do you declare state? What is it?
ASKER
Please test and fix this code:
<%@ Page Language="VB" AutoEventWireup="false" %>
<%
Dim array(,) As Object = { _
{"ak","Alaska"}, _
{"al","Alabama"}, _
{"ca","California"} _
}
Dim Xyz As String = "Lakes in ak are cold cold but it is always hot in AL and can be hot or cold in ca"
Response.Write(xyz)
' Should say:
' Lakes in Alaska are cold cold but it is always hot in Alabama and can be hot or cold in California
%>
Here is your problem:
xyz = xyz.Replace(" " & state & " ", " " & states(state) & " ")
change to this:
xyz = xyz.Replace(" " & states & " ", " " & state(states) & " ")
either that or change this:
For Each (states as string in state.Keys)
to be this:
For Each (state as string in states.Keys)
and make sure states is the array
xyz = xyz.Replace(" " & state & " ", " " & states(state) & " ")
change to this:
xyz = xyz.Replace(" " & states & " ", " " & state(states) & " ")
either that or change this:
For Each (states as string in state.Keys)
to be this:
For Each (state as string in states.Keys)
and make sure states is the array
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
CodeCruiser, your code does not work for me. Please test this, thanks.
<%@ Page Language="VB" AutoEventWireup="false" %>
<%
Dim states As New Dictionary(of string, string)
states.add("AK", "Alaska")
states.add("AL", "Albama")
states.add("CA", "California")
Dim Xyz As String = "Lakes in ak are cold cold but it is always hot in AL and can be hot or cold in ca"
For Each (states as string in state.Keys)
xyz = xyz.Replace(" " & state & " ", " " & states(state) & " ")
Next
Response.Write(xyz)
' Should say:
' Lakes in Alaska are cold cold but it is always hot in Alabama and can be hot or cold in California
%>
I see you have plenty of help, so im going to bow out of this one. Good day folk :)
ASKER
Thank you all. With your help I got it working.
I have asked a related question here:
https://www.experts-exchange.com/questions/27868078/ASP-NET-VB-REGEX-Case-Insensitive-and-at-beginning-middle-or-end.html
I have asked a related question here:
https://www.experts-exchange.com/questions/27868078/ASP-NET-VB-REGEX-Case-Insensitive-and-at-beginning-middle-or-end.html
<%@ Page Language="VB" AutoEventWireup="false" %>
<%
Dim states As New Dictionary(of string, string)
states.add("AK", "Alaska")
states.add("AL", "Albama")
states.add("CA", "California")
Dim Xyz As String = "Lakes in ak are cold cold but it is always hot in AL and can be hot or cold in ca"
For Each state In states
xyz = xyz.Replace(" " & state.Key & " ", " " & state.Value & " ")
Next
Response.Write(xyz)
' Should say:
' Lakes in Alaska are cold cold but it is always hot in Alabama and can be hot or cold in California
%>
Following code works for me but only if state abbreviations are in caps
Dim states As New Dictionary(Of String, String)
states.add("AK", "Alaska")
states.add("AL", "Albama")
states.add("CA", "California")
Dim Xyz As String = "Lakes in AK are cold cold but it is always hot in AL and can be hot or cold in CA"
For Each state As String In states.Keys
Xyz = Xyz.Replace(" " & state, " " & states(state.ToUpper) & " ")
Next
Dim states As New Dictionary(Of String, String)
states.add("AK", "Alaska")
states.add("AL", "Albama")
states.add("CA", "California")
Dim Xyz As String = "Lakes in AK are cold cold but it is always hot in AL and can be hot or cold in CA"
For Each state As String In states.Keys
Xyz = Xyz.Replace(" " & state, " " & states(state.ToUpper) & " ")
Next