Connecting Tech Pros Worldwide Forums | Help | Site Map

Very strange thing. Why does this happens?

Shapper
Guest
 
Posts: n/a
#1: Nov 19 '05

Hello,

I have this code:

[1] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
[2] Select Case Session("culture")
[3] Case "pt-PT"
[4] ...
[5] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
[6] Response.Write("1")
[7] Case "en-GB"
[8] ...
[9] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
[10] Response.Write("2")
[11] Case Else
[12] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
[13] Response.Write("3")
[14] End Select

[15] ddlculture.DataSource = cultureList
[16] ddlculture.DataBind()

Something very strange is happening:
If I declare cultureList in line [1] and delete the lines [5], [9] and
[12] everything works fine. However, if I declare the string inside the
case, i.e., I keep lines [5], [9] and [12] but delete the line [1] I get
an error on line [15] saying: "Name 'cultureList' is not declared."

Why is this? Isn't this strange?

And yes the case is working. That is why I have the Response.Write
lines.

Thanks,
Miguel


Matt Dockerty
Guest
 
Posts: n/a
#2: Nov 19 '05

re: Very strange thing. Why does this happens?


Not sure what it's like for you VB folk but in C# we have to define
variables in the scope in which they will be used - so a Dim inside the case
statement only defines a variable at that level.

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:e0JDakUXFHA.2080@TK2MSFTNGP15.phx.gbl...[color=blue]
>
> Hello,
>
> I have this code:
>
> [1] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
> [2] Select Case Session("culture")
> [3] Case "pt-PT"
> [4] ...
> [5] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
> [6] Response.Write("1")
> [7] Case "en-GB"
> [8] ...
> [9] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
> [10] Response.Write("2")
> [11] Case Else
> [12] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
> [13] Response.Write("3")
> [14] End Select
>
> [15] ddlculture.DataSource = cultureList
> [16] ddlculture.DataBind()
>
> Something very strange is happening:
> If I declare cultureList in line [1] and delete the lines [5], [9] and
> [12] everything works fine. However, if I declare the string inside the
> case, i.e., I keep lines [5], [9] and [12] but delete the line [1] I get
> an error on line [15] saying: "Name 'cultureList' is not declared."
>
> Why is this? Isn't this strange?
>
> And yes the case is working. That is why I have the Response.Write
> lines.
>
> Thanks,
> Miguel
>[/color]


Shapper
Guest
 
Posts: n/a
#3: Nov 19 '05

re: Very strange thing. Why does this happens?


Wow,

Probably in VB is the same. Didn't know that.

I have been programming in other languages so things become a mess here.

Thanks,
Miguel

"Matt Dockerty" <Ps reply to group> wrote in message news:Ps reply to
group:
[color=blue]
> Not sure what it's like for you VB folk but in C# we have to define
> variables in the scope in which they will be used - so a Dim inside the case
> statement only defines a variable at that level.
>
> "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
> news:e0JDakUXFHA.2080@TK2MSFTNGP15.phx.gbl...
>[color=green]
> >
> > Hello,
> >
> > I have this code:
> >
> > [1] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
> > [2] Select Case Session("culture")
> > [3] Case "pt-PT"
> > [4] ...
> > [5] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
> > [6] Response.Write("1")
> > [7] Case "en-GB"
> > [8] ...
> > [9] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
> > [10] Response.Write("2")
> > [11] Case Else
> > [12] Dim cultureList(,) As String = {{"E", "en-GB"}, {"P", "pt-PT"}}
> > [13] Response.Write("3")
> > [14] End Select
> >
> > [15] ddlculture.DataSource = cultureList
> > [16] ddlculture.DataBind()
> >
> > Something very strange is happening:
> > If I declare cultureList in line [1] and delete the lines [5], [9] and
> > [12] everything works fine. However, if I declare the string inside the
> > case, i.e., I keep lines [5], [9] and [12] but delete the line [1] I get
> > an error on line [15] saying: "Name 'cultureList' is not declared."
> >
> > Why is this? Isn't this strange?
> >
> > And yes the case is working. That is why I have the Response.Write
> > lines.
> >
> > Thanks,
> > Miguel
> >[/color][/color]

Closed Thread