Solved

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

Posted on 2010-08-18
3
321 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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    747 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now