Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default array question

    hi, this is a piece of code from a program.

    ----
    my $size;
    my $realPath;
    my @filterArray;
    open READFILTEREDLIST,'</tmp/FILTEREDLIST' or die "Datei kann nicht
    geoeffnet werden: $!\n";

    while(<READFILTEREDLIST>) {

    @filterArray=<READFILTEREDLIST>;

    }
    close READFILTEREDLIST;

    open (WRITEPATHS, ">/tmp/FILTEREDPATHS") or die "Datei konnte nicht
    gefunden werden";
    print "open \n";
    foreach(@filterArray){

    print "array: $_\n"; #NOTHING!!!
    (my $datei, my $pfad)=fileparse($_);
    ($size, $realPath)=split('\s', $pfad);
    print "path: $realPath\n";
    print WRITEPATHS "$realPath\n";

    }
    close WRITEPATHS;

    ----

    the file FILTEREDLIST contains something like:

    132k /var/backups/dpkg.status.1.gz
    132k /var/backups/dpkg.status.2.gz
    124k /var/backups/dpkg.status.3.gz
    8.0k /var/log/auth.log.1.gz
    12k /var/log/auth.log.2.gz
    4.0k /var/log/auth.log.3.gz
    12k /var/log/daemon.log.1.gz
    12k /var/log/daemon.log.2.gz
    8.0k /var/log/daemon.log.3.gz
    8.0k /var/log/debug.1.gz
    12k /var/log/debug.2.gz
    4.0k /var/log/debug.3.gz
    8.0k /var/log/kern.log.1.gz
    4.0k /var/log/kern.log.2.gz
    8.0k /var/log/kern.log.3.gz
    8.0k /var/log/messages.1.gz
    8.0k /var/log/messages.2.gz
    8.0k /var/log/messages.3.gz
    4.0k /var/log/setuid.changes.1.gz

    but when i want to read that into the array, something does wrong. the
    array is always empty, do you see the mistake? the file is not
    empty...

    THANKS!!
    Math55 Guest

  2. Similar Questions and Discussions

    1. 2-Dimensional Array Question
      This is my first time using an array. 1. My code seems to work but I need to return a count from each piece of the array (the number of each...
    2. array question help
      i am new to arrays and have practiced some tutorials for instance aligning information in rows and columns then categorizing them numerically,...
    3. simple array question?
      On 12-Aug-2003, "Randell D." <you.can.email.me.at.randelld@yahoo.com> wrote: http://www.php.net/manual/en/function.list.php -- Tom...
    4. array question (grep -v on array)
      Hi, I have an output of errors fed into an array, after which I only look at things I care about and put them in a different array: ...
    5. [PHP] ARRAY QUESTION
      Dale Hersh <mailto:dalehersh@hotmail.com> on Thursday, July 24, 2003 12:41 PM said: unset($myStuff);
  3. #2

    Default Re: array question

    [email]magelord@t-online.de[/email] (Math55) writes:
    > Subject: array question
    Please put the subject of your post in the Subject of your post. If
    in doubt try this simple test. Imagine you could have been bothered
    to have done a search before you posted. Next imagine you found a
    thread with your subject line. Would you have been able to recognise
    it as the same subject?

    If your subject truely refects your level of understanding of your
    problem (which appears to be a question about reading files) then you
    have not thought about your problem anywhere near enough thought to
    dream of asking anyone else for help.

    Math55, your poor subject lines have been pointed out to you before by
    a number of people. Do you realise how rude you are being by still
    not making any effort?
    > my @filterArray;
    > while(<READFILTEREDLIST>) {
    >
    > @filterArray=<READFILTEREDLIST>;
    >
    > }
    Where did you learn that construct?

    The above is an obfucated way of writing...

    scalar <READFILTEREDLIST>; # Discard first line
    my @filterArray=<READFILTEREDLIST>; # Read remainder of file into array
    > the file FILTEREDLIST contains something like:
    >
    > 132k /var/backups/dpkg.status.1.gz
    > 132k /var/backups/dpkg.status.2.gz
    > 124k /var/backups/dpkg.status.3.gz
    > 8.0k /var/log/auth.log.1.gz
    > 12k /var/log/auth.log.2.gz
    > 4.0k /var/log/auth.log.3.gz
    > 12k /var/log/daemon.log.1.gz
    > 12k /var/log/daemon.log.2.gz
    > 8.0k /var/log/daemon.log.3.gz
    > 8.0k /var/log/debug.1.gz
    > 12k /var/log/debug.2.gz
    > 4.0k /var/log/debug.3.gz
    > 8.0k /var/log/kern.log.1.gz
    > 4.0k /var/log/kern.log.2.gz
    > 8.0k /var/log/kern.log.3.gz
    > 8.0k /var/log/messages.1.gz
    > 8.0k /var/log/messages.2.gz
    > 8.0k /var/log/messages.3.gz
    > 4.0k /var/log/setuid.changes.1.gz
    >
    > but when i want to read that into the array, something does wrong. the
    > array is always empty, do you see the mistake?
    Are you sure the file actually contains more than one line (as
    determined by the EOL sequence for your OS)?

    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\@
    . l___\\
    # ll l\\
    ###LL LL\\
    Brian McCauley Guest

  4. #3

    Default Re: array question

    Math55 <magelord@t-online.de> wrote in comp.lang.perl.misc:
    > hi, this is a piece of code from a program.
    >
    > ----
    > my $size;
    > my $realPath;
    > my @filterArray;
    > open READFILTEREDLIST,'</tmp/FILTEREDLIST' or die "Datei kann nicht
    > geoeffnet werden: $!\n";
    >
    > while(<READFILTEREDLIST>) {
    This reads one line from the file into $_
    >
    > @filterArray=<READFILTEREDLIST>;
    This reads the rest of the lines into @filterArray.
    >
    > }
    > close READFILTEREDLIST;
    >
    > open (WRITEPATHS, ">/tmp/FILTEREDPATHS") or die "Datei konnte nicht
    > gefunden werden";
    > print "open \n";
    > foreach(@filterArray){
    >
    > print "array: $_\n"; #NOTHING!!!
    > (my $datei, my $pfad)=fileparse($_);
    ^^^^^^^^^
    The function "fileparse()" is nowhere defined. So the program exits
    the first time through the loop.
    > ($size, $realPath)=split('\s', $pfad);
    > print "path: $realPath\n";
    > print WRITEPATHS "$realPath\n";
    The variable "$realPath" is never assigned to. "$pfad" isn't even
    declared. If the program compiles for you, you are not using "strict",
    which is bad.
    >
    > }
    > close WRITEPATHS;
    >
    > ----
    >
    > the file FILTEREDLIST contains something like:
    >
    > 132k /var/backups/dpkg.status.1.gz
    > 132k /var/backups/dpkg.status.2.gz
    > 124k /var/backups/dpkg.status.3.gz
    [more data snipped]

    Your diagnosis is wrong. The file *is* read into the array (save for
    the first line, and after getting compile-time errors out of the way).
    I don't know why you think it isn't.

    To get the whole file, do away with the while-loop and just say

    @filterArray=<READFILTEREDLIST>;

    Anno
    Anno Siegel Guest

  5. #4

    Default Re: array question

    This is balderdash. Ignore me.

    Graham

    Graham Wood wrote:
    > > while(<READFILTEREDLIST>) {
    > >
    > > @filterArray=<READFILTEREDLIST>;
    > >
    > > }
    > > close READFILTEREDLIST;
    >
    > Here's where I think your problem lies.
    >
    > while(<READFILTEREDLIST>){ }
    > steps through each line of the file returning the contents in $_ each time
    >
    > @filterArray=<READFILTEREDLIST>;
    > reads the rest of the file contents into @filterArray.
    >
    > If you do both of these at the same time you will end up with nothing in
    > @filterArray because this is happening
    >
    > 1. While loop reads a line
    > 2. @filterArray gets all the rest of the lines
    > 3. While loop reads a line
    > 4. @filterArray gets the rest of the lines
    >
    > This will repeat until the while loop reads the last line and then
    > <READFILTEREDLIST> will return nothing to @filterArray then your script will
    > proceed with the lines after the while loop.
    >
    > You either need to use a while loop or @array=<FILEHANDLE> not both at the same
    > time.
    >
    > while(<READFILTEREDLIST>){
    > push(@filterArray,$_);
    > }
    >
    > OR
    >
    > @filterArray=<READFILTEREDLIST>;
    >
    > Hope this helps
    >
    > Graham
    Graham Wood Guest

  6. #5

    Default Re: array question


    On Thu, Jun 26, by accident I became aware that Graham Wood
    had caused the following to appear:

    Parts/Attachments:
    1 Shown 48 lines Text (charset: UTF-8)
    2 OK 8 lines Text (charset: UTF-8), "Card for Graham Wood"
    ----------------------------------------

    [ The following text is in the "UTF-8" character set. ]


    and had then inscribed on the eternal scroll:
    > This is balderdash. Ignore me.
    That's OK. Usenet postings with attachments normally get ignored by
    my newsreader. I had temporarily lifted the normal filters for a
    different reason, otherwise I'd never have seen those non-conformant
    postings.

    all the best
    Alan J. Flavell Guest

  7. #6

    Default Re: array question

    Math55 <magelord@t-online.de> wrote:
    > while(<READFILTEREDLIST>) {
    >
    > @filterArray=<READFILTEREDLIST>;

    The while() reads the first line into the $_ variable, then
    you never do anything with that first line...

    > ($size, $realPath)=split('\s', $pfad);

    A pattern match should *look like* a pattern match.

    Space characters are not a scarce resource. Feel free to use as
    many as you like to make your code easier to read and understand:


    ($size, $realPath) = split( /\s/, $pfad );


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  8. #7

    Default Re: array question

    Alan J. Flavell <flavell@mail.cern.ch> wrote:
    > On Thu, Jun 26, by accident I became aware that Graham Wood
    > had caused the following to appear:
    >> This is balderdash. Ignore me.
    >
    > Usenet postings with attachments normally get ignored by
    > my newsreader.

    By mine too.

    Sometimes I think my scorefile is prescient. :-)


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  9. #8

    Default ARRAY QUESTION

    I have a question regarding the count function. Here goes:

    Lets pretend I have this array called myStuff. If I add two elements to
    myStuff and call the count function, I will get a result of 2. My question
    is how do I re-initialize the array after adding elements so when I call the
    count function on the array, I get a result of 0.

    Thanks,
    Dale


    Dale Hersh Guest

  10. #9

    Default Re: ARRAY QUESTION


    "Dale Hersh" <dalehersh@hotmail.com> wrote in message
    news:20030724193903.81534.qmail@pb1.pair.com...
    > I have a question regarding the count function. Here goes:
    >
    > Lets pretend I have this array called myStuff. If I add two elements to
    > myStuff and call the count function, I will get a result of 2. My question
    > is how do I re-initialize the array after adding elements so when I call
    the
    > count function on the array, I get a result of 0.
    >
    > Thanks,
    > Dale
    I assume you want to KEEP the other values in the array? If not then you
    can just unset($myStuff).

    If you do want to keep the array intact then I suppose you could store the
    count in a variable $counta, add more elements to the array (or not), take
    the count again and store it in a new variable $countb, then subtract the
    values $count = abs($counta - $countb);

    abs() converts to the absolute value if the result is negative.

    - Kevin


    Kevin Stone Guest

  11. #10

    Default Array question

    I'm looking to make an admin page for a web photo gallery, and I need
    to make a drop down menu showing all files in a given directory that
    do not have comments in a database for the given filename.

    I'm curious about the most efficient way to do this. I don't want to
    query the database separately for each file as this would be horribly
    inefficient. I'm thinking about two arrays, one containing all
    filenames in the photo directory, and one containing filenames from
    the database that have descriptions.

    Is there a simple way in ADO to do a set operation on arrays, that is
    to produce array C that has all elements in array A that are not
    contained in array B?

    I can do this with while loops, but there must be a better way!

    John
    John Hoge Guest

  12. #11

    Default Re: Array question

    Do all the filenames exist in the database or is this a loosely coupled
    system where there may be more or less images in the directory than exist in
    the database?

    Chris.

    "John Hoge" <jhoge123@yahoo.com> wrote in message
    news:d0f2d316.0307241519.cd5f34c@posting.google.co m...
    I'm looking to make an admin page for a web photo gallery, and I need
    to make a drop down menu showing all files in a given directory that
    do not have comments in a database for the given filename.

    I'm curious about the most efficient way to do this. I don't want to
    query the database separately for each file as this would be horribly
    inefficient. I'm thinking about two arrays, one containing all
    filenames in the photo directory, and one containing filenames from
    the database that have descriptions.

    Is there a simple way in ADO to do a set operation on arrays, that is
    to produce array C that has all elements in array A that are not
    contained in array B?

    I can do this with while loops, but there must be a better way!

    John


    Chris Barber Guest

  13. #12

    Default Re: Array question

    sounds like fun

    I got sick of working on my own photo solutions and now I use this
    so far I really like it

    [url]http://www.cjwsoft.com/aspgallery/default.asp[/url]




    "Chris Barber" <chris@blue-canoe.co.uk.NOSPAM> wrote in message
    news:%23iij9LkUDHA.360@TK2MSFTNGP11.phx.gbl...
    > Do all the filenames exist in the database or is this a loosely coupled
    > system where there may be more or less images in the directory than exist
    in
    > the database?
    >
    > Chris.
    >
    > "John Hoge" <jhoge123@yahoo.com> wrote in message
    > news:d0f2d316.0307241519.cd5f34c@posting.google.co m...
    > I'm looking to make an admin page for a web photo gallery, and I need
    > to make a drop down menu showing all files in a given directory that
    > do not have comments in a database for the given filename.
    >
    > I'm curious about the most efficient way to do this. I don't want to
    > query the database separately for each file as this would be horribly
    > inefficient. I'm thinking about two arrays, one containing all
    > filenames in the photo directory, and one containing filenames from
    > the database that have descriptions.
    >
    > Is there a simple way in ADO to do a set operation on arrays, that is
    > to produce array C that has all elements in array A that are not
    > contained in array B?
    >
    > I can do this with while loops, but there must be a better way!
    >
    > John
    >
    >

    James Monroe Guest

  14. #13

    Default Re: Array question

    A better fix would be to control the graphic files when added.

    Allow a file upload only with a comment through an asp page.

    You can then control file size limits and file naming convention
    and maintain all the data in the database.

    -------------------------------------------------
    d l b j r

    Unambit from meager knowledge of inane others,
    engender uncharted sagacity.
    -------------------------------------------------


    dlbjr Guest

  15. #14

    Default Re: Array question

    Chris,

    I didn't want to mess with a file upload component, so I just FTP the
    image files to a specific directory. After they are on the website, I
    use the admin page to enter the filename & caption into a database. I
    originally thought I would just key in the filenames as they are
    uploaded, which works just fine.

    A better admin page would look for any files in the gallery directory
    that are not in database and populate a drop down menu with them. So I
    want to create one array from a scripting.filesystemobject with every
    filename in the directory, and create a second with each entry in the
    database, and run a set operation to leave only those filenames that
    are in the image directory but not in the database.

    Perhaps I'm looking for more out of ASP than it can do, but I think
    it's always a good idea to look for innovative solutions rather than
    just cranking out inefficient code.

    Thanks a lot,

    John

    "Chris Barber" <chris@blue-canoe.co.uk.NOSPAM> wrote in message news:<#iij9LkUDHA.360@TK2MSFTNGP11.phx.gbl>...
    > Do all the filenames exist in the database or is this a loosely coupled
    > system where there may be more or less images in the directory than exist in
    > the database?
    >
    > Chris.
    >
    > "John Hoge" <jhoge123@yahoo.com> wrote in message
    > news:d0f2d316.0307241519.cd5f34c@posting.google.co m...
    > I'm looking to make an admin page for a web photo gallery, and I need
    > to make a drop down menu showing all files in a given directory that
    > do not have comments in a database for the given filename.
    >
    > I'm curious about the most efficient way to do this. I don't want to
    > query the database separately for each file as this would be horribly
    > inefficient. I'm thinking about two arrays, one containing all
    > filenames in the photo directory, and one containing filenames from
    > the database that have descriptions.
    >
    > Is there a simple way in ADO to do a set operation on arrays, that is
    > to produce array C that has all elements in array A that are not
    > contained in array B?
    >
    > I can do this with while loops, but there must be a better way!
    >
    > John
    John Hoge Guest

  16. #15

    Default Array Question

    hello everyone,

    I am trying to store one of the fields of the resultset into an array
    as I display the results.

    while ($row = mysql_fetch_array($result1)) {

    // Alternate the bgcolor of each row for visibility
    ($even % 2) == 0 ? $bgcolor = "#EFEFEF" : $bgcolor =
    "#eeffff";
    $even = $even + 1;

    // print the actual row
    echo "<TR BGCOLOR=$bgcolor>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
    Arial, Helvetica, sans-serif\">$row[company]</font></TD>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
    Arial, Helvetica, sans-serif\">$row[name_1]</font></TD>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
    Arial, Helvetica, sans-serif\">$row[phone_1]</font></TD>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
    Arial, Helvetica, sans-serif\">$row[city]</font></TD>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
    Arial, Helvetica, sans-serif\">$row[url]</font></TD>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana,
    Arial, Helvetica, sans-serif\">$row[email_1]</font></TD>
    <TD align=\"center\"><font color=\"#333333\" size=\"1\"
    face=\"Verdana, Arial, Helvetica, sans-serif\"><a
    href=\"full-profile.php?name=".$row['company']."\">--Link--</a></
    font></TD>
    </TR>";

    // try to store the name of the company in an array called companyname

    $companyname = array($row['company']);

    // try to register the variable

    $_SESSION['link'] = $companyname;
    //$_SESSION['link'] = $row[company];

    } // end while



    I am trying to store the variable $row['company'] into a array called
    companyname[], so that I am able to register it as a session variable
    and use it on subsequent pages. I keep getting errors and am not able
    to store the values in array $row['company'] . I would appreciate if
    someone could throw some light on this.

    Thanks in advance.
    --Pushpinder

    Pushpinder Singh Garcha Guest

  17. #16

    Default array question

    in an ASP page i loop through my record set and i need to put some records
    in an array but i can't figure it out, can u please help me ?


    <%
    i = 1
    Do While Not objpaginaRS.EOF

    ArrayPages(i) = objpaginaRS("paginaid")

    i= i+ 1
    objpaginaRS.MoveNext
    Loop
    %>

    <%
    ShowArrayInTable(ArrayPages)

    Sub ShowArrayInTable(ArrayToShow)
    ArraySize = (UBound(ArrayToShow) - LBound(ArrayToShow)) + 1

    Response.Write ArraySize & "<br>"

    For i = LBound(ArrayToShow) To UBound(ArrayToShow)
    Response.Write "<b>" & i & "</b>"
    Response.Write ArrayToShow(i) & "<br>"
    Next

    End Sub
    %>


    ziemon Guest

  18. #17

    Default Re: array question

    Try this:

    if not objpaginaRS.EOF then
    ArrayPages = objpaginaRS.GetRows(,,array("paginaid"))
    End if
    objpaginaRS.Close
    Set objpaginaRS = nothing
    If not IsArray(ArrayPages) Then
    Response.Write "No records were returned"
    Else
    Response.Write Ubound(ArrayPages,2) - 1 & "<br>"
    For i = 0 to Ubound(ArrayPages,2)
    Response.Write "<b>" & i & "</b>"
    Response.Write ArrayPages(0,i) & "<br>"
    next
    End if

    HTH,
    Bob Barrows

    ziemon wrote:
    > in an ASP page i loop through my record set and i need to put some
    > records in an array but i can't figure it out, can u please help me ?
    >
    >
    > <%
    > i = 1
    > Do While Not objpaginaRS.EOF
    >
    > ArrayPages(i) = objpaginaRS("paginaid")
    >
    > i= i+ 1
    > objpaginaRS.MoveNext
    > Loop
    > %>
    >
    > <%
    > ShowArrayInTable(ArrayPages)
    >
    > Sub ShowArrayInTable(ArrayToShow)
    > ArraySize = (UBound(ArrayToShow) - LBound(ArrayToShow)) + 1
    >
    > Response.Write ArraySize & "<br>"
    >
    > For i = LBound(ArrayToShow) To UBound(ArrayToShow)
    > Response.Write "<b>" & i & "</b>"
    > Response.Write ArrayToShow(i) & "<br>"
    > Next
    >
    > End Sub
    > %>


    Bob Barrows Guest

  19. #18

    Default Re: array question

    <%
    i = 1
    Do While Not objPaginaRS.EOF

    ArrayPages(i) = objpaginaRS("paginaID")

    i = i + 1
    objpaginaRS.MoveNext
    Loop

    'Now you know how many of these guys u got
    myCount = i - 1
    %>

    <%

    Sub ShowArrayInTable()
    For i = 1 To myCount
    Response.Write "<b>" & i & "</b>"
    Response.Write ArrayPages(i) & "<br>"
    Next
    End Sub

    'Call the Procedure
    ShowArrayInTable()
    %>

    its all quite simple, you see?




    "ziemon" <news@ziemon.nl> wrote in message
    news:blic99$3mf$1@news4.tilbu1.nb.home.nl...
    > in an ASP page i loop through my record set and i need to put some records
    > in an array but i can't figure it out, can u please help me ?
    >
    >
    > <%
    > i = 1
    > Do While Not objpaginaRS.EOF
    >
    > ArrayPages(i) = objpaginaRS("paginaid")
    >
    > i= i+ 1
    > objpaginaRS.MoveNext
    > Loop
    > %>
    >
    > <%
    > ShowArrayInTable(ArrayPages)
    >
    > Sub ShowArrayInTable(ArrayToShow)
    > ArraySize = (UBound(ArrayToShow) - LBound(ArrayToShow)) + 1
    >
    > Response.Write ArraySize & "<br>"
    >
    > For i = LBound(ArrayToShow) To UBound(ArrayToShow)
    > Response.Write "<b>" & i & "</b>"
    > Response.Write ArrayToShow(i) & "<br>"
    > Next
    >
    > End Sub
    > %>
    >
    >

    Hannibal Guest

  20. #19

    Default Re: array question

    Uuummm - looping through a recordset to put its data into an array is not
    very efficient. Use GetRows ... see my previous reply in this thread - oh,
    that was 5 days ago, so you might have missed it. There's always Google.

    Bob
    Hannibal wrote:
    > <%
    > i = 1
    > Do While Not objPaginaRS.EOF
    >
    > ArrayPages(i) = objpaginaRS("paginaID")
    >
    > i = i + 1
    > objpaginaRS.MoveNext
    > Loop
    >
    > 'Now you know how many of these guys u got
    > myCount = i - 1
    > %>
    >
    > <%
    >
    > Sub ShowArrayInTable()
    > For i = 1 To myCount
    > Response.Write "<b>" & i & "</b>"
    > Response.Write ArrayPages(i) & "<br>"
    > Next
    > End Sub
    >
    > 'Call the Procedure
    > ShowArrayInTable()
    > %>
    >
    > its all quite simple, you see?
    >
    >
    >
    >
    > "ziemon" <news@ziemon.nl> wrote in message
    > news:blic99$3mf$1@news4.tilbu1.nb.home.nl...
    >> in an ASP page i loop through my record set and i need to put some
    >> records in an array but i can't figure it out, can u please help me ?
    >>
    >>
    >> <%
    >> i = 1
    >> Do While Not objpaginaRS.EOF
    >>
    >> ArrayPages(i) = objpaginaRS("paginaid")
    >>
    >> i= i+ 1
    >> objpaginaRS.MoveNext
    >> Loop
    >> %>
    >>
    >> <%
    >> ShowArrayInTable(ArrayPages)
    >>
    >> Sub ShowArrayInTable(ArrayToShow)
    >> ArraySize = (UBound(ArrayToShow) - LBound(ArrayToShow)) + 1
    >>
    >> Response.Write ArraySize & "<br>"
    >>
    >> For i = LBound(ArrayToShow) To UBound(ArrayToShow)
    >> Response.Write "<b>" & i & "</b>"
    >> Response.Write ArrayToShow(i) & "<br>"
    >> Next
    >>
    >> End Sub
    >> %>

    Bob Barrows Guest

  21. #20

    Default Re: array question

    hehehe... i must apologise for that sad excuse of an answer...

    i was not looking at the bigger picture, merely fixing ths code i saw in
    front of me...

    there's a much easier way to display the data WITHOUT creating array's
    etc...

    actually i use it as part of a web based sql management system of mine...
    <table blah blah>
    <%
    'do the headings/column names
    Response.Write "<tr>"
    For Each Item in Rs.Fields
    Response.Write "<th>" & Item.Name & "</th>"
    Next
    Response.Write "</tr>"

    'then do the rows of data
    Do while (Not Rs.eof)
    Response.Write "<tr>"
    For Index=0 to (Rs.fields.count-1)
    Response.Write "<TD VAlign=top>" & Rs(Index) & "&nbsp;</TD>"
    Next
    Response.Write "</tr>"
    Rs.MoveNext
    Loop

    %>
    </table>

    hope sumone finds it usefull too.



    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:OMaiIYPjDHA.4036@tk2msftngp13.phx.gbl...
    > Uuummm - looping through a recordset to put its data into an array is not
    > very efficient. Use GetRows ... see my previous reply in this thread - oh,
    > that was 5 days ago, so you might have missed it. There's always Google.
    >
    > Bob
    > Hannibal wrote:
    > > <%
    > > i = 1
    > > Do While Not objPaginaRS.EOF
    > >
    > > ArrayPages(i) = objpaginaRS("paginaID")
    > >
    > > i = i + 1
    > > objpaginaRS.MoveNext
    > > Loop
    > >
    > > 'Now you know how many of these guys u got
    > > myCount = i - 1
    > > %>
    > >
    > > <%
    > >
    > > Sub ShowArrayInTable()
    > > For i = 1 To myCount
    > > Response.Write "<b>" & i & "</b>"
    > > Response.Write ArrayPages(i) & "<br>"
    > > Next
    > > End Sub
    > >
    > > 'Call the Procedure
    > > ShowArrayInTable()
    > > %>
    > >
    > > its all quite simple, you see?
    > >
    > >
    > >
    > >
    > > "ziemon" <news@ziemon.nl> wrote in message
    > > news:blic99$3mf$1@news4.tilbu1.nb.home.nl...
    > >> in an ASP page i loop through my record set and i need to put some
    > >> records in an array but i can't figure it out, can u please help me ?
    > >>
    > >>
    > >> <%
    > >> i = 1
    > >> Do While Not objpaginaRS.EOF
    > >>
    > >> ArrayPages(i) = objpaginaRS("paginaid")
    > >>
    > >> i= i+ 1
    > >> objpaginaRS.MoveNext
    > >> Loop
    > >> %>
    > >>
    > >> <%
    > >> ShowArrayInTable(ArrayPages)
    > >>
    > >> Sub ShowArrayInTable(ArrayToShow)
    > >> ArraySize = (UBound(ArrayToShow) - LBound(ArrayToShow)) + 1
    > >>
    > >> Response.Write ArraySize & "<br>"
    > >>
    > >> For i = LBound(ArrayToShow) To UBound(ArrayToShow)
    > >> Response.Write "<b>" & i & "</b>"
    > >> Response.Write ArrayToShow(i) & "<br>"
    > >> Next
    > >>
    > >> End Sub
    > >> %>
    >
    >

    Hannibal Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139