Very strange thing. Why does this happens?

Discussion in 'ASP .Net' started by Shapper, May 20, 2005.

  1. Shapper

    Shapper Guest

    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
    Shapper, May 20, 2005
    #1
    1. Advertising

  2. 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:...
    >
    > 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, May 20, 2005
    #2
    1. Advertising

  3. Shapper

    Shapper Guest

    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:

    > 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:...
    >
    > >
    > > 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
    > >
    Shapper, May 20, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,840
    Smokey Grindel
    Dec 2, 2006
  2. NM
    Replies:
    6
    Views:
    465
    Default User
    Sep 20, 2006
  3. Replies:
    1
    Views:
    477
    Mark Rae [MVP]
    Sep 20, 2007
  4. Nicole
    Replies:
    36
    Views:
    1,206
    Awful Dog Autry
    Mar 1, 2009
  5. ericnoonan
    Replies:
    0
    Views:
    345
    ericnoonan
    Dec 14, 2009
Loading...

Share This Page