Redefined variable

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

    Redefined variable

    Hi everybody,

    In an ASP page, I need to load twice an include file that contains
    variables. So I get an error message "variable redefine" I tried to test

    with VarType before to define the variable (dim) with no success. Is it
    faisable with VBScript to define a variable (dim) under condition.

    ' this code gives an error
    if VarType("MyVar" ) = vbNull then
    dim MyVar
    end if


    many thank's
    serge



  • Jeff Cochran

    #2
    Re: Redefined variable

    On Sun, 18 Jul 2004 10:19:51 -0300, Serge Myrand
    <info@softdelir ium.qc.ca> wrote:
    [color=blue]
    >In an ASP page, I need to load twice an include file that contains
    >variables. So I get an error message "variable redefine" I tried to test[/color]

    Why would you need to include a file twice? If it has different
    values for the variables, name them differently and include them once.
    [color=blue]
    >with VarType before to define the variable (dim) with no success. Is it
    >faisable with VBScript to define a variable (dim) under condition.[/color]

    No.
    [color=blue]
    >' this code gives an error
    >if VarType("MyVar" ) = vbNull then
    > dim MyVar
    >end if[/color]

    Hmm... Using a variable before defining it, why would that cause an
    error?

    You can REDIM if needed, but rethink your code and do it correctly the
    first time.

    Jeff

    Comment

    • Bob Lehmann

      #3
      Re: Redefined variable

      Why do you need to load it twice?

      Bob Lehmann

      "Serge Myrand" <info@softdelir ium.qc.ca> wrote in message
      news:40FA78F7.B 87E06B3@softdel irium.qc.ca...[color=blue]
      > Hi everybody,
      >
      > In an ASP page, I need to load twice an include file that contains
      > variables. So I get an error message "variable redefine" I tried to test
      >
      > with VarType before to define the variable (dim) with no success. Is it
      > faisable with VBScript to define a variable (dim) under condition.
      >
      > ' this code gives an error
      > if VarType("MyVar" ) = vbNull then
      > dim MyVar
      > end if
      >
      >
      > many thank's
      > serge
      >
      >
      >[/color]


      Comment

      • Rob Collyer

        #4
        Re: Redefined variable

        One way, would be to lose 'option explicit' and all your variable
        declarations (dim statements)

        Although I have to say, including a file more than once is generally a sign
        of bad coding practice....

        I'm sure there will be a much much better way of achieving what you want
        without resorting to including the same file multiple times.
        --
        Rob Collyer - www.webforumz.com
        Web design and development forums for Free help, advice,
        tips, and website critique by professional designers and developers.



        "Serge Myrand" <info@softdelir ium.qc.ca> wrote in message
        news:40FA78F7.B 87E06B3@softdel irium.qc.ca...[color=blue]
        > Hi everybody,
        >
        > In an ASP page, I need to load twice an include file that contains
        > variables. So I get an error message "variable redefine" I tried to test
        >
        > with VarType before to define the variable (dim) with no success. Is it
        > faisable with VBScript to define a variable (dim) under condition.
        >
        > ' this code gives an error
        > if VarType("MyVar" ) = vbNull then
        > dim MyVar
        > end if
        >
        >
        > many thank's
        > serge
        >
        >
        >[/color]


        Comment

        • Serge Myrand

          #5
          Re: Redefined variable

          Hi,

          Because this is a menu bar and there is an option taht allow the user to put
          it at the bottom and at the top of the page.

          serge

          Jeff Cochran wrote:
          [color=blue]
          > On Sun, 18 Jul 2004 10:19:51 -0300, Serge Myrand
          > <info@softdelir ium.qc.ca> wrote:
          >[color=green]
          > >In an ASP page, I need to load twice an include file that contains
          > >variables. So I get an error message "variable redefine" I tried to test[/color]
          >
          > Why would you need to include a file twice? If it has different
          > values for the variables, name them differently and include them once.
          >[color=green]
          > >with VarType before to define the variable (dim) with no success. Is it
          > >faisable with VBScript to define a variable (dim) under condition.[/color]
          >
          > No.
          >[color=green]
          > >' this code gives an error
          > >if VarType("MyVar" ) = vbNull then
          > > dim MyVar
          > >end if[/color]
          >
          > Hmm... Using a variable before defining it, why would that cause an
          > error?
          >
          > You can REDIM if needed, but rethink your code and do it correctly the
          > first time.
          >
          > Jeff[/color]

          Comment

          • Serge Myrand

            #6
            Re: Redefined variable

            Hi,
            see my answer to Jeff above

            serge

            Bob Lehmann wrote:
            [color=blue]
            > Why do you need to load it twice?
            >
            > Bob Lehmann
            >
            > "Serge Myrand" <info@softdelir ium.qc.ca> wrote in message
            > news:40FA78F7.B 87E06B3@softdel irium.qc.ca...[color=green]
            > > Hi everybody,
            > >
            > > In an ASP page, I need to load twice an include file that contains
            > > variables. So I get an error message "variable redefine" I tried to test
            > >
            > > with VarType before to define the variable (dim) with no success. Is it
            > > faisable with VBScript to define a variable (dim) under condition.
            > >
            > > ' this code gives an error
            > > if VarType("MyVar" ) = vbNull then
            > > dim MyVar
            > > end if
            > >
            > >
            > > many thank's
            > > serge
            > >
            > >
            > >[/color][/color]

            Comment

            • Serge Myrand

              #7
              Re: Redefined variable

              Hi,

              see my answer to Jeff above

              thank's
              serge


              Rob Collyer wrote:
              [color=blue]
              > One way, would be to lose 'option explicit' and all your variable
              > declarations (dim statements)
              >
              > Although I have to say, including a file more than once is generally a sign
              > of bad coding practice....
              >
              > I'm sure there will be a much much better way of achieving what you want
              > without resorting to including the same file multiple times.
              > --
              > Rob Collyer - www.webforumz.com
              > Web design and development forums for Free help, advice,
              > tips, and website critique by professional designers and developers.
              >
              > "Serge Myrand" <info@softdelir ium.qc.ca> wrote in message
              > news:40FA78F7.B 87E06B3@softdel irium.qc.ca...[color=green]
              > > Hi everybody,
              > >
              > > In an ASP page, I need to load twice an include file that contains
              > > variables. So I get an error message "variable redefine" I tried to test
              > >
              > > with VarType before to define the variable (dim) with no success. Is it
              > > faisable with VBScript to define a variable (dim) under condition.
              > >
              > > ' this code gives an error
              > > if VarType("MyVar" ) = vbNull then
              > > dim MyVar
              > > end if
              > >
              > >
              > > many thank's
              > > serge
              > >
              > >
              > >[/color][/color]

              Comment

              • Bob Lehmann

                #8
                Re: Redefined variable

                OK. So why don't you put it in a function and call the function to output
                the menu?

                Function TheMenu
                TheMenu = "Some HTML for the menu"
                End Function

                If MenuPreference ="top" Then
                Response.Write TheMenu
                End If

                Bob Lehmann

                "Serge Myrand" <info@softdelir ium.qc.ca> wrote in message
                news:40FAB199.A CA8146C@softdel irium.qc.ca...[color=blue]
                > Hi,
                > see my answer to Jeff above
                >
                > serge
                >
                > Bob Lehmann wrote:
                >[color=green]
                > > Why do you need to load it twice?
                > >
                > > Bob Lehmann
                > >
                > > "Serge Myrand" <info@softdelir ium.qc.ca> wrote in message
                > > news:40FA78F7.B 87E06B3@softdel irium.qc.ca...[color=darkred]
                > > > Hi everybody,
                > > >
                > > > In an ASP page, I need to load twice an include file that contains
                > > > variables. So I get an error message "variable redefine" I tried to[/color][/color][/color]
                test[color=blue][color=green][color=darkred]
                > > >
                > > > with VarType before to define the variable (dim) with no success. Is[/color][/color][/color]
                it[color=blue][color=green][color=darkred]
                > > > faisable with VBScript to define a variable (dim) under condition.
                > > >
                > > > ' this code gives an error
                > > > if VarType("MyVar" ) = vbNull then
                > > > dim MyVar
                > > > end if
                > > >
                > > >
                > > > many thank's
                > > > serge
                > > >
                > > >
                > > >[/color][/color]
                >[/color]


                Comment

                • Jeff Cochran

                  #9
                  Re: Redefined variable

                  On Sun, 18 Jul 2004 14:19:29 -0300, Serge Myrand
                  <info@softdelir ium.qc.ca> wrote:
                  [color=blue]
                  >Because this is a menu bar and there is an option taht allow the user to put
                  >it at the bottom and at the top of the page.[/color]

                  So? Do this:

                  [Menubar.asp]

                  <%
                  Sub Menubar
                  Dim Menubar1, Menubar2
                  ...Menubar code...
                  End Sub
                  %>

                  [Page.asp]

                  <!--#include virtual="menuba r.asp"-->

                  <%
                  Menubar
                  Response.Write "Page text and stuff..."
                  Menubar
                  %>

                  Learn to use subs and functions.

                  Jeff

                  [color=blue]
                  >serge
                  >
                  >Jeff Cochran wrote:
                  >[color=green]
                  >> On Sun, 18 Jul 2004 10:19:51 -0300, Serge Myrand
                  >> <info@softdelir ium.qc.ca> wrote:
                  >>[color=darkred]
                  >> >In an ASP page, I need to load twice an include file that contains
                  >> >variables. So I get an error message "variable redefine" I tried to test[/color]
                  >>
                  >> Why would you need to include a file twice? If it has different
                  >> values for the variables, name them differently and include them once.
                  >>[color=darkred]
                  >> >with VarType before to define the variable (dim) with no success. Is it
                  >> >faisable with VBScript to define a variable (dim) under condition.[/color]
                  >>
                  >> No.
                  >>[color=darkred]
                  >> >' this code gives an error
                  >> >if VarType("MyVar" ) = vbNull then
                  >> > dim MyVar
                  >> >end if[/color]
                  >>
                  >> Hmm... Using a variable before defining it, why would that cause an
                  >> error?
                  >>
                  >> You can REDIM if needed, but rethink your code and do it correctly the
                  >> first time.
                  >>
                  >> Jeff[/color][/color]

                  Comment

                  Working...