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

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

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

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. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    731
    Raymond Hettinger
    Jul 27, 2003
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    1,373
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,842
    Smokey Grindel
    Dec 2, 2006
  4. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    2,065
    Merrill & Michele
    Oct 19, 2004
  5. NM
    Replies:
    6
    Views:
    724
    Default User
    Sep 20, 2006
  6. Replies:
    1
    Views:
    705
    Mark Rae [MVP]
    Sep 20, 2007
  7. Nicole
    Replies:
    36
    Views:
    1,484
    Awful Dog Autry
    Mar 1, 2009
  8. ericnoonan
    Replies:
    0
    Views:
    515
    ericnoonan
    Dec 14, 2009
Loading...