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

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

LVL 25
kevp75Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
nmarunConnect With a Mentor Commented:
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
 
nmarunCommented:
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
     
    kevp75Author Commented:
    thank you
    0
    All Courses

    From novice to tech pro — start learning today.