Monday, March 26, 2012

This drives me crazy

Hello,
I have this:
Select Case Session("culture4web")
Case "pt-PT"
Dim topMenuItems() As String = {"Home", "Conteúdos", "Xtras", " ", "Web", "Company"}
Case "en-GB"
Dim topMenuItems() As String = {"Home", "Conteúdos", "Xtras", " ", "Web", "Company"}
End Select
Call_Function (topMenuItems)
I am having problems because the variable disapears outside of Case Statement.
How can I solve this?
Thanks,
Miguel

Always try and define your variables outside conditional statements...
Dim topMenuItems() As String
Select Case Session("culture4web")
Case "pt-PT"
topMenuItems()= {"Home", "Conteúdos", "Xtras", " ", "Web", "Company"}
Case "en-GB"
topMenuItems() = {"Home", "Conteúdos", "Xtras", " ", "Web", "Company"}
End Select

.NET introduced an extended scoping model, block-level variables are now block-local.
Declare your dependant variables outside theSelect...End Select block:
Dim topMenuItem() As String
Select Case Session("culture4web")
Case "pt-PT"
topMenuItems = {"Home", "Conteúdos", "Xtras", " ", "Web", "Company"}
End Select
Call_Function(topMenuItems)

0 comments:

Post a Comment