Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 978
  • Last Modified:

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

%>

Open in new window

0
hankknight
Asked:
hankknight
  • 5
  • 4
  • 3
  • +1
3 Solutions
 
aprestoCommented:
You arent calling the array anything are you?!:

Dim array(,) As Object = { _
0
 
aprestoCommented:
Please ignore that last comment, moment of temporary insanity, just looking at it now :)
0
 
aprestoCommented:
What line does the compiler complain about?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hankknightAuthor Commented:
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)
                              ~~~~~      

Open in new window

0
 
YZlatCommented:
try this:

Dim array(,) As Object
ReDim array(3,3)  As String = { _
     {"ak","Alaska"}, _
     {"al","Alabama"}, _
     {"ca","California"} _
}
0
 
YZlatCommented:
or better yet

Dim array(,) As Object = New Object(,) { _
     {"ak","Alaska"}, _
     {"al","Alabama"}, _
     {"ca","California"} _
}

Open in new window

0
 
YZlatCommented:
where do you declare state? What is it?
0
 
hankknightAuthor Commented:
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

%>

Open in new window

0
 
aprestoCommented:
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
0
 
CodeCruiserCommented:
You are still using the array? I replaced that with a Dictionary<string, string> in my code.
0
 
hankknightAuthor Commented:
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

%>

Open in new window

0
 
aprestoCommented:
I see you have plenty of help, so im going to bow out of this one. Good day folk :)
0
 
hankknightAuthor Commented:
Thank you all.  With your help I got it working.  

I have asked a related question here:

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_27868078.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

%>

Open in new window

0
 
CodeCruiserCommented:
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
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now