Contants and Parameter Name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dwg1011

    #1

    Contants and Parameter Name

    I have a global class GClass with 2 contants. Both are declared public in the
    form:

    PUBLIC Const Const1 = "xxx". When I try to use the constant as a default
    value (see code excerpt below) the program bombs, but when I use a hardcoded
    value it works fine. Any ideas?

    Failing Version:

    <SelectParamete rs>
    <asp:Paramete r Name="Catalog" Type="String"
    DefaultValue="< %
    GClass.Const1 %>" />

    Working Version:

    <SelectParamete rs>
    <asp:Paramete r Name="Catalog" Type="String"
    DefaultValue="x xx" />

    Thanks,
    David


  • V

    #2
    Re: Contants and Parameter Name

    To access it like this, you would need to declare your constant as
    static.

    - V

    dwg1011 wrote:
    I have a global class GClass with 2 contants. Both are declared public in the
    form:
    >
    PUBLIC Const Const1 = "xxx". When I try to use the constant as a default
    value (see code excerpt below) the program bombs, but when I use a hardcoded
    value it works fine. Any ideas?
    >
    Failing Version:
    >
    <SelectParamete rs>
    <asp:Paramete r Name="Catalog" Type="String"
    DefaultValue="< %
    GClass.Const1 %>" />
    >
    Working Version:
    >
    <SelectParamete rs>
    <asp:Paramete r Name="Catalog" Type="String"
    DefaultValue="x xx" />
    >
    Thanks,
    David

    Comment

    • Göran Andersson

      #3
      Re: Contants and Parameter Name

      You can't declare a constant as static.

      V wrote:
      To access it like this, you would need to declare your constant as
      static.
      >
      - V
      >
      dwg1011 wrote:
      >I have a global class GClass with 2 contants. Both are declared public in the
      >form:
      >>
      >PUBLIC Const Const1 = "xxx". When I try to use the constant as a default
      >value (see code excerpt below) the program bombs, but when I use a hardcoded
      >value it works fine. Any ideas?
      >>
      >Failing Version:
      >>
      ><SelectParamet ers>
      > <asp:Paramete r Name="Catalog" Type="String"
      > DefaultValue="< %
      >GClass.Const 1 %>" />
      >>
      >Working Version:
      >>
      ><SelectParamet ers>
      > <asp:Paramete r Name="Catalog" Type="String"
      > DefaultValue="x xx" />
      >>
      >Thanks,
      >David
      >

      Comment

      • Göran Andersson

        #4
        Re: Contants and Parameter Name

        Unless you have ported the framework to an Atari, I don't really think
        that the program bombs. ;)

        What error message do you get? Often the error message tells you exactly
        what is wrong.

        dwg1011 wrote:
        I have a global class GClass with 2 contants. Both are declared public in the
        form:
        >
        PUBLIC Const Const1 = "xxx". When I try to use the constant as a default
        value (see code excerpt below) the program bombs, but when I use a hardcoded
        value it works fine. Any ideas?
        >
        Failing Version:
        >
        <SelectParamete rs>
        <asp:Paramete r Name="Catalog" Type="String"
        DefaultValue="< %
        GClass.Const1 %>" />
        >
        Working Version:
        >
        <SelectParamete rs>
        <asp:Paramete r Name="Catalog" Type="String"
        DefaultValue="x xx" />
        >
        Thanks,
        David
        >
        >

        Comment

        • V

          #5
          Re: Contants and Parameter Name

          What I meant is that the constant that he is declaring, he should make
          it a static variable, because he is trying to access it using the Class
          name.

          You are right, that you cannot declare a constant static. :)

          - V

          Göran Andersson wrote:
          You can't declare a constant as static.
          >
          V wrote:
          To access it like this, you would need to declare your constant as
          static.

          - V

          dwg1011 wrote:
          I have a global class GClass with 2 contants. Both are declared publicin the
          form:
          >
          PUBLIC Const Const1 = "xxx". When I try to use the constant as a default
          value (see code excerpt below) the program bombs, but when I use a hardcoded
          value it works fine. Any ideas?
          >
          Failing Version:
          >
          <SelectParamete rs>
          <asp:Paramete r Name="Catalog" Type="String"
          DefaultValue="< %
          GClass.Const1 %>" />
          >
          Working Version:
          >
          <SelectParamete rs>
          <asp:Paramete r Name="Catalog" Type="String"
          DefaultValue="x xx" />
          >
          Thanks,
          David

          Comment

          • Andrew Morton

            #6
            Re: Contants and Parameter Name

            dwg1011 wrote:
            I have a global class GClass with 2 contants. Both are declared
            public in the form:
            >
            PUBLIC Const Const1 = "xxx". When I try to use the constant as a
            default value (see code excerpt below) the program bombs, but when I
            use a hardcoded value it works fine. Any ideas?
            >
            Failing Version:
            >
            <SelectParamete rs>
            <asp:Paramete r Name="Catalog"
            Type="String"
            DefaultValue="< %
            GClass.Const1 %>" />
            Shouldn't that be:-
            <asp:Paramete r Name="Catalog"
            Type="String"
            DefaultValue="< %=GClass.Const1 %>" />

            ?

            i.e. no new line splitting the name/value pair to potentially confuse it,
            and an equals sign.

            Andrew


            Comment

            • dwg1011

              #7
              Re: Contants and Parameter Name

              The spacing was just the way it posted. If I am not mistaken the =varname is
              "classic" ASP formatting while .net does not require it.

              David

              "Andrew Morton" wrote:
              dwg1011 wrote:
              I have a global class GClass with 2 contants. Both are declared
              public in the form:

              PUBLIC Const Const1 = "xxx". When I try to use the constant as a
              default value (see code excerpt below) the program bombs, but when I
              use a hardcoded value it works fine. Any ideas?

              Failing Version:

              <SelectParamete rs>
              <asp:Paramete r Name="Catalog"
              Type="String"
              DefaultValue="< %
              GClass.Const1 %>" />
              >
              Shouldn't that be:-
              <asp:Paramete r Name="Catalog"
              Type="String"
              DefaultValue="< %=GClass.Const1 %>" />
              >
              ?
              >
              i.e. no new line splitting the name/value pair to potentially confuse it,
              and an equals sign.
              >
              Andrew
              >
              >
              >

              Comment

              • Andrew Morton

                #8
                Re: Contants and Parameter Name

                >dwg1011 wrote:
                >>I have a global class GClass with 2 contants. Both are declared
                >>public in the form:
                >>>
                >>PUBLIC Const Const1 = "xxx". When I try to use the constant as a
                >>default value (see code excerpt below) the program bombs, but when I
                >>use a hardcoded value it works fine. Any ideas?
                >>>
                >>Failing Version:
                >>>
                >><SelectParame ters>
                >> <asp:Paramete r Name="Catalog"
                >> Type="String"
                >>DefaultValue= "<%
                >>GClass.Cons t1 %>" />
                >>
                "Andrew Morton" wrote:
                >Shouldn't that be:-
                ><asp:Paramet er Name="Catalog"
                > Type="String"
                > DefaultValue="< %=GClass.Const1 %>" />
                >>
                >?
                >>
                >i.e. no new line splitting the name/value pair to potentially
                >confuse it, and an equals sign.
                dwg1011 wrote:
                The spacing was just the way it posted. If I am not mistaken the
                =varname is "classic" ASP formatting while .net does not require it.
                Did you try it? I only use code-behind rather than in-line code.

                What actually goes wrong? "Bombs" is vague.


                *However* I now think it can't work that way. You would have to do it like:-

                <%@ Page Language="VB" %>
                <script runat="server">
                Const const1 as string="xxx"
                Sub Page_Load(obj as object, e as eventargs)
                Catalog.Default Value=const1
                End Sub
                </script>
                [other stuff]
                <SelectParamete rs>
                <asp:Paramete r Id="Catalog" Name="Catalog" Type="String" />

                Any use?

                Andrew


                Comment

                Working...