Solved

Array To Linq ...  Variable Not Declared...

Posted on 2010-08-18
3
327 Views
Last Modified: 2013-11-11
Can anyone tell me why the following is happenning?

Name 'Query2' is not declared

in the following code....  please not, if I Dim the Query2 prior to the condition statements, I cannot use the LINQ Query


If ZipCM.Security.CanAccess(New Integer() {1, 2, 3, 4, 5}) Then
                    Dim Query2 = From nl In Query1(i).ToString().Split("|") Where nl(1) = "0" And (nl(2) = "1" Or nl(2) = "2")
                ElseIf Not (ZipCM.Security.CanAccess(New Integer() {1, 2, 3, 4, 5})) Then
                    Dim Query2 = From nl In Query1(i).ToString().Split("|") Where nl(1) = "0" And (nl(2) = "0" Or nl(2) = "2")
                Else
                    Dim Query2 = From nl In Query1(i).ToString().Split("|") Where nl(1) = "0" And (nl(2) = "2")
                End If

                tmpNav.Append("<li class=""site_nav"">" & Query2(2).ToString() & "</li>" & vbCrLf)

Open in new window

0
Comment
Question by:kevp75
  • 2
3 Comments
 
LVL 27

Expert Comment

by:nmarun
ID: 33467968
Query2 is declared only inside the 'if' block, so it's visibility is scoped within the 'if' block. That's the reason why it throws that error. Why don't you copy the 'tmpNav.Append(...' statement in every segment of the if block?If ZipCM.Security.CanAccess(New Integer() {1, 2, 3, 4, 5}) Then                    Dim Query2 = From nl In Query1(i).ToString().Split("|") Where nl(1) = "0" And (nl(2) = "1" Or nl(2) = "2")                    tmpNav.Append("
  • " & Query2(2).ToString() & "
  • " & vbCrLf)                ElseIf Not (ZipCM.Security.CanAccess(New Integer() {1, 2, 3, 4, 5})) Then                    Dim Query2 = From nl In Query1(i).ToString().Split("|") Where nl(1) = "0" And (nl(2) = "0" Or nl(2) = "2")                    tmpNav.Append("
  • " & Query2(2).ToString() & "
  • " & vbCrLf)                Else                    Dim Query2 = From nl In Query1(i).ToString().Split("|") Where nl(1) = "0" And (nl(2) = "2")                    tmpNav.Append("
  • " & Query2(2).ToString() & "
  • " & vbCrLf)                End IfArun
    0
     
    LVL 27

    Accepted Solution

    by:
    nmarun earned 500 total points
    ID: 33467999
    Not sure why it got posted that way, but here's another attempt:



    If ZipCM.Security.CanAccess(New Integer() {1, 2, 3, 4, 5}) Then
                       Dim Query2 = From nl In Query1(i).ToString().Split("|") Where nl(1) = "0" And (nl(2) = "1" Or nl(2) = "2")
                       tmpNav.Append("<li class=""site_nav"">" & Query2(2).ToString() & "</li>" & vbCrLf)
                   ElseIf Not (ZipCM.Security.CanAccess(New Integer() {1, 2, 3, 4, 5})) Then
                       Dim Query2 = From nl In Query1(i).ToString().Split("|") Where nl(1) = "0" And (nl(2) = "0" Or nl(2) = "2")
                       tmpNav.Append("<li class=""site_nav"">" & Query2(2).ToString() & "</li>" & vbCrLf)
                   Else
                       Dim Query2 = From nl In Query1(i).ToString().Split("|") Where nl(1) = "0" And (nl(2) = "2")
                       tmpNav.Append("<li class=""site_nav"">" & Query2(2).ToString() & "</li>" & vbCrLf)
                   End If
    

    Open in new window

    0
     
    LVL 25

    Author Closing Comment

    by:kevp75
    ID: 33468169
    thank you
    0

    Featured Post

    DevOps Toolchain Recommendations

    Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

    Question has a verified solution.

    If you are experiencing a similar issue, please ask a related question

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
    Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

    777 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question