Solved

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

Posted on 2010-08-18
3
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

    NEW Veeam Agent for Microsoft Windows

    Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

    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)…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
    This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

    622 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