SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    looping variable

    I have a quick question. I have a variable that goes through a loop, and each time it appends the new value to the end using a comma. Example:

    1st time through:
    a = 1
    2nd time through:
    a = 1, 4
    3rd time through:
    a = 1, 4, 2


    So now after my loop is all done I have this value where each value is seperated by a comma. What I want to do is compare each of the values and display only the largest number. Any ideas on how to do this? Thanks

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,266
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Not quite sure where the source of the numbers is. A recordset? An array?

    Anyway, do you mean something like this?

    Code:
    Dim LargestValue    :  LargestValue = 0
    
    ' Assuming a recordset...
    Do while not rs.eof
       HoldValue = clng(rs("returnedvalue"))
       if HoldValue > LargestValue then
          LargestValue = HoldValue
       end if
       OutputString = OutputString & "," & HoldValue
       rs.MoveNext
    Loop
    At the end, LargestValue would hold the largest value entered into the string...
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  3. #3
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or a variation on this Wrox exercise.

    Code:
    <%
    Dim strText, intSpace, strWord, intCounter
    intSpace = 1
    strText ="the quick brown fox jumped over the lazy dog"
    For intCounter = 1 To len(strText)+1
    If mid(strText,intCounter,1) = " " Or intCounter = len(strText)+1 Then
    strWord = mid(strText,intSpace,intCounter-intSpace)
    intSpace = intCounter
    strWord = trim(strWord)
    %>

  4. #4
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This is just pulling out the three values again. I need to show just the largest number of the value, without commas.

  5. #5
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well once you've pulled out the values it's a doddle to just do an If or a function to find the highest one ... check the value -- if it's the highest so far, keep it, if it's not, overwrite it with the current one .......

  6. #6
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    nevermind I figured it out, I was displaying the wrong variable

  7. #7
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Let me throw this one out there. I got the largest number, now I'm trying for smallest with no luck...code:

    HoldValue2 = averagetime
    if HoldValue2 < LargestValue2 then
    LargestValue2 = HoldValue2
    holduser1 = user1
    end if

    Problem is since largestvalue2 starts off equalling 0 then no number is ever going to be lower than 0. I tried starting largestvalue2 at a large number with no luck. Any ideas?

  8. #8
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are your values ever 0?

  9. #9
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No, the only value that starts off zero is the largestvalue2, but since it starts off as 0 then nothing will ever be smaller.

  10. #10
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,266
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    The why not do something like this in your if statement: If HoldValue < SmallestValue OR SmallestValue = 0 then
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse


Bookmarks

Posting Permissions

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