Very strange thing. Why does this happens?

S

Shapper

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
 
M

Matt Dockerty

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.
 
S

Shapper

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

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top