Array Integers vs Array Variables

Discussion in 'ASP General' started by Rob Meade, Feb 8, 2004.

  1. Rob Meade

    Rob Meade Guest

    "Roland Hall" wrote...

    > Dim b
    > b = 10
    > Dim a(b) ' this errors out but
    > Dim a() ' this
    > Redim a(b) ' works


    I had exactly the same problem at work a few months back, just used the
    redim in the end and it seemed ok - just assumed it was by design...

    Rob
    Rob Meade, Feb 8, 2004
    #1
    1. Advertising

  2. Rob Meade

    Evertjan. Guest

    Roland Hall wrote on 08 feb 2004 in
    microsoft.public.inetserver.asp.general:

    > Dim b
    > b = 10
    > Dim a(b) ' this errors out but
    > Dim a() ' this
    > Redim a(b) ' works
    >



    b = 101
    Redim a(b)
    response.write ubound(a)

    Look, mama, no dims!

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Feb 8, 2004
    #2
    1. Advertising

  3. Rob Meade

    Ray at Guest

    True, you must use an actual number when dimming an array, because the array
    is put in memory with the Dim statement before any variables are evaluated,
    b in this case.

    --

    Ray at home
    Microsoft ASP MVP


    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    > In working with arrays, I have found that I am unable to dimension and

    array
    > with a variable that has an integer value but I can redimension one this
    > way. I haven't see any information that tells me if this is a

    requirement,
    > although it appears to be because I get an error if I try it.
    >
    > Ex.
    >
    > Dim b
    > b = 10
    > Dim a(b) ' this errors out but
    > Dim a() ' this
    > Redim a(b) ' works
    >
    >
    > --
    > Roland Hall
    > /* This information is distributed in the hope that it will be useful, but
    > without any warranty; without even the implied warranty of merchantability
    > or fitness for a particular purpose. */
    > Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    > WSH 5.6 Documentation -

    http://msdn.microsoft.com/downloads/list/webdev.asp
    > MSDN Library - http://msdn.microsoft.com/library/default.asp
    >
    >
    Ray at, Feb 8, 2004
    #3
  4. Rob Meade

    Ray at Guest

    My Mom would yell at me if I didn't Dim. And she'd be right in doing so!

    --

    Ray at home
    Microsoft ASP MVP


    "Evertjan." <> wrote in message
    news:Xns94897455F1EE2eejj99@194.109.133.20...

    >
    > b = 101
    > Redim a(b)
    > response.write ubound(a)
    >
    > Look, mama, no dims!
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
    Ray at, Feb 8, 2004
    #4
  5. Rob Meade

    Evertjan. Guest

    Ray at <%=sLocation%> [MVP] wrote on 08 feb 2004 in
    microsoft.public.inetserver.asp.general:

    > My Mom would yell at me if I didn't Dim.
    > And she'd be right in doing so!


    She must have a dim view of you.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Feb 8, 2004
    #5
  6. Rob Meade

    Roland Hall Guest

    In working with arrays, I have found that I am unable to dimension and array
    with a variable that has an integer value but I can redimension one this
    way. I haven't see any information that tells me if this is a requirement,
    although it appears to be because I get an error if I try it.

    Ex.

    Dim b
    b = 10
    Dim a(b) ' this errors out but
    Dim a() ' this
    Redim a(b) ' works


    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
    Roland Hall, Feb 8, 2004
    #6
  7. Rob Meade

    Ray at Guest

    "Evertjan." <> wrote in message
    news:Xns948975EB0CBDCeejj99@194.109.133.20...
    > Ray at <%=sLocation%> [MVP] wrote on 08 feb 2004 in
    > microsoft.public.inetserver.asp.general:
    >
    > > My Mom would yell at me if I didn't Dim.
    > > And she'd be right in doing so!

    >
    > She must have a dim view of you.


    I am a multidimensional Ray, as she dimmed me to be.

    Ray at home
    Ray at, Feb 8, 2004
    #7
  8. Rob Meade

    Rob Meade Guest

    "Evertjan." wrote ...

    > She must have a dim view of you.


    baadoom-tish! :eek:)

    Rob
    Rob Meade, Feb 8, 2004
    #8
  9. Rob Meade

    Rob Meade Guest

    "Roland Hall" wrote...

    > I came to the same conclusion so I was looking for some
    > reasoning other than that's how it works.


    ah...

    > I'm not being facetious.


    I know :)

    > It's nice to know I'm not completely crazy until someone posts with

    something I'm missing, I guess.

    I wouldn't make those conclusions based on my posts alone Roland :eek:D

    Regards

    Rob
    Rob Meade, Feb 8, 2004
    #9
  10. Rob Meade

    Roland Hall Guest

    "Rob Meade" wrote:
    : "Roland Hall" wrote...
    :
    : > Dim b
    : > b = 10
    : > Dim a(b) ' this errors out but
    : > Dim a() ' this
    : > Redim a(b) ' works
    :
    : I had exactly the same problem at work a few months back, just used the
    : redim in the end and it seemed ok - just assumed it was by design...

    Thanks Rob. I came to the same conclusion so I was looking for some
    reasoning other than that's how it works. I'm not being facetious. I
    really appreciate the feedback. I just didn't understand why if
    redimensioning it works when dimensioning doesn't and have not see any
    literature to explain it. It's nice to know I'm not completely crazy until
    someone posts with something I'm missing, I guess. (O:=

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
    Roland Hall, Feb 8, 2004
    #10
  11. Rob Meade

    Ray at Guest

    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    > "Ray at <%=sLocation%> [MVP]" wrote:'
    > : True, you must use an actual number when dimming an array, because the
    > array
    > : is put in memory with the Dim statement before any variables are
    > evaluated,
    > : b in this case.
    >
    > But I already dimensioned b and it is in memory and I'm just creating a
    > reference to b, aren't I?



    b has been dimmed, but it doesn't have a value yet when the code is
    compiled. It doesn't get a value (b=10) until after all the compiling has
    finished. Part of the compiling process, as I believe, is making room in
    memory for the variables (dim). That, and checking for unterminated
    strings, syntax errors, etc. So, if you're the script interpreter, you'd go
    to declare an array in memory and see that you should make room for "b"
    elements. But you do not know what b is, as you have not yet gotten to the
    point at which you start reading lines like "b=10." I guess you could
    parallel this logic with why you cannot do <!-- #include
    file="<%varName%>" -->. That's a different thing, of course, but the logic
    behind why you cannot do it is the same, if that helps at all.

    Ray at home
    Ray at, Feb 8, 2004
    #11
  12. Rob Meade

    Ray at Guest

    Redim is run-time and Dim is compile-time.

    Ray at home

    "Roland Hall" <nobody@nowhere> wrote in message
    news:...

    >
    > That's great but that's not my question. My question is, if it was not
    > clear, why must I use an integer value for Dim when I don't have to for
    > ReDim.
    >
    > --
    > Roland Hall
    > /* This information is distributed in the hope that it will be useful, but
    > without any warranty; without even the implied warranty of merchantability
    > or fitness for a particular purpose. */
    > Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    > WSH 5.6 Documentation -

    http://msdn.microsoft.com/downloads/list/webdev.asp
    > MSDN Library - http://msdn.microsoft.com/library/default.asp
    >
    >
    Ray at, Feb 8, 2004
    #12
  13. Rob Meade

    Roland Hall Guest

    "Ray at <%=sLocation%> [MVP]" wrote:'
    : True, you must use an actual number when dimming an array, because the
    array
    : is put in memory with the Dim statement before any variables are
    evaluated,
    : b in this case.

    But I already dimensioned b and it is in memory and I'm just creating a
    reference to b, aren't I?

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
    Roland Hall, Feb 8, 2004
    #13
  14. Rob Meade

    Roland Hall Guest

    "Evertjan." wrote:
    : Roland Hall wrote on 08 feb 2004 in
    : microsoft.public.inetserver.asp.general:
    :
    : > Dim b
    : > b = 10
    : > Dim a(b) ' this errors out but
    : > Dim a() ' this
    : > Redim a(b) ' works
    : >
    :
    :
    : b = 101
    : Redim a(b)
    : response.write ubound(a)

    That's great but that's not my question. My question is, if it was not
    clear, why must I use an integer value for Dim when I don't have to for
    ReDim.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
    Roland Hall, Feb 8, 2004
    #14
  15. Rob Meade

    Evertjan. Guest

    Ray at <%=sLocation%> [MVP] wrote on 08 feb 2004 in
    microsoft.public.inetserver.asp.general:

    > Redim is run-time and Dim is compile-time.


    I think this is the reason.

    But it is only of historical importance since, I think, the difference
    between dim and redim could be easily set aside in ASP vbs, and the two
    could be made internaly and specification-aly equivalent without any
    problem in backward compatibility.

    Long ago fixed data memory was set aside in the exe file, to improve speed
    at the expence of bigger exe files, because of the strange ways that the
    8088/80x86 chip was designed to handle memory.

    68000 chip assembler programmers, used to continuous memory adressing,
    could only smile.

    Perhaps dim and redim are already the same code, only superficially made
    different for auld long time sake ?

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Feb 8, 2004
    #15
  16. Rob Meade

    Roland Hall Guest

    "Ray at <%=sLocation%> [MVP]" wrote:
    : "Roland Hall" <nobody@nowhere> wrote in message
    : news:...
    : > "Ray at <%=sLocation%> [MVP]" wrote:'
    : > : True, you must use an actual number when dimming an array, because the
    : > array
    : > : is put in memory with the Dim statement before any variables are
    : > evaluated,
    : > : b in this case.
    : >
    : > But I already dimensioned b and it is in memory and I'm just creating a
    : > reference to b, aren't I?
    :
    :
    : b has been dimmed, but it doesn't have a value yet when the code is
    : compiled. It doesn't get a value (b=10) until after all the compiling has
    : finished. Part of the compiling process, as I believe, is making room in
    : memory for the variables (dim). That, and checking for unterminated
    : strings, syntax errors, etc. So, if you're the script interpreter, you'd
    go
    : to declare an array in memory and see that you should make room for "b"
    : elements. But you do not know what b is, as you have not yet gotten to
    the
    : point at which you start reading lines like "b=10." I guess you could
    : parallel this logic with why you cannot do <!-- #include
    : file="<%varName%>" -->. That's a different thing, of course, but the
    logic
    : behind why you cannot do it is the same, if that helps at all.

    Yes, this with your other post that Dim is compile-time and ReDim is
    run-time makes sense.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
    Roland Hall, Feb 8, 2004
    #16
  17. Rob Meade

    Roland Hall Guest

    "Ray at <%=sLocation%> [MVP]" wrote:
    : Redim is run-time and Dim is compile-time.

    Ok, so if I:

    dim a(4)

    and then I

    redim(4000)

    Memory still has to be set aside for the additional increase. Is memory
    used with the initial and then point to the rest additional area or is just
    a pointer placed in the original memory location with all of the memory now
    stored somewhere else or is the original memory location abandoned once the
    redim is run and only the new memory location is used because the original
    location is never called again and really doesn't associate with the new
    dimension, or does it? That might be the longest question I've ever
    written. (O:=

    Is there documentation showing how memory is managed with ASP or does it
    pass off that handling to something else, like the server or the OS itself?

    The reason I'm asking, if that makes a difference is if I better understand
    how memory is stored and referenced, it might help me to improve the
    performance of my applications.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
    Roland Hall, Feb 8, 2004
    #17
    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:
    9
    Views:
    7,965
    Ralf Hildebrandt
    Jan 19, 2005
  2. Replies:
    12
    Views:
    14,498
    Lee Ryman
    Apr 26, 2005
  3. Replies:
    9
    Views:
    935
  4. Royan
    Replies:
    32
    Views:
    988
  5. Huub
    Replies:
    14
    Views:
    159
Loading...

Share This Page