Redefined variable

Discussion in 'ASP General' started by Serge Myrand, Jul 18, 2004.

  1. Serge Myrand

    Serge Myrand Guest

    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
    Serge Myrand, Jul 18, 2004
    #1
    1. Advertising

  2. Serge Myrand

    Jeff Cochran Guest

    On Sun, 18 Jul 2004 10:19:51 -0300, Serge Myrand
    <> wrote:

    >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


    Why would you need to include a file twice? If it has different
    values for the variables, name them differently and include them once.

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


    No.

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


    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
    Jeff Cochran, Jul 18, 2004
    #2
    1. Advertising

  3. Serge Myrand

    Bob Lehmann Guest

    Why do you need to load it twice?

    Bob Lehmann

    "Serge Myrand" <> wrote in message
    news:...
    > 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
    >
    >
    >
    Bob Lehmann, Jul 18, 2004
    #3
  4. Serge Myrand

    Rob Collyer Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    >
    Rob Collyer, Jul 18, 2004
    #4
  5. Serge Myrand

    Serge Myrand Guest

    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:

    > On Sun, 18 Jul 2004 10:19:51 -0300, Serge Myrand
    > <> wrote:
    >
    > >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

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

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

    >
    > 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
    Serge Myrand, Jul 18, 2004
    #5
  6. Serge Myrand

    Serge Myrand Guest

    Hi,
    see my answer to Jeff above

    serge

    Bob Lehmann wrote:

    > Why do you need to load it twice?
    >
    > Bob Lehmann
    >
    > "Serge Myrand" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > >
    Serge Myrand, Jul 18, 2004
    #6
  7. Serge Myrand

    Serge Myrand Guest

    Hi,

    see my answer to Jeff above

    thank's
    serge


    Rob Collyer wrote:

    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > >
    Serge Myrand, Jul 18, 2004
    #7
  8. Serge Myrand

    Bob Lehmann Guest

    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" <> wrote in message
    news:...
    > Hi,
    > see my answer to Jeff above
    >
    > serge
    >
    > Bob Lehmann wrote:
    >
    > > Why do you need to load it twice?
    > >
    > > Bob Lehmann
    > >
    > > "Serge Myrand" <> wrote in message
    > > news:...
    > > > 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
    > > >
    > > >
    > > >

    >
    Bob Lehmann, Jul 18, 2004
    #8
  9. Serge Myrand

    Jeff Cochran Guest

    On Sun, 18 Jul 2004 14:19:29 -0300, Serge Myrand
    <> wrote:

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


    So? Do this:

    [Menubar.asp]

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

    [Page.asp]

    <!--#include virtual="menubar.asp"-->

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

    Learn to use subs and functions.

    Jeff


    >serge
    >
    >Jeff Cochran wrote:
    >
    >> On Sun, 18 Jul 2004 10:19:51 -0300, Serge Myrand
    >> <> wrote:
    >>
    >> >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

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

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

    >>
    >> 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
    Jeff Cochran, Jul 19, 2004
    #9
    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. Replies:
    1
    Views:
    624
    Victor Bazarov
    Apr 1, 2005
  2. Wei Li

    function redefined problem

    Wei Li, Aug 25, 2004, in forum: C Programming
    Replies:
    11
    Views:
    689
    Wei Li
    Aug 27, 2004
  3. irfanhab
    Replies:
    1
    Views:
    458
    Nick Keighley
    Aug 23, 2006
  4. deanfamily
    Replies:
    4
    Views:
    403
    puzzlecracker
    Oct 24, 2005
  5. MiG
    Replies:
    8
    Views:
    137
    Ryan Leavengood
    Oct 19, 2005
Loading...

Share This Page