Solved

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

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

    Free Tool: SSL Checker

    Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

    One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

    Question has a verified solution.

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

    It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

    830 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