Results 1 to 3 of 3

Thread: Efficient looping

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    90

    Efficient looping

    I would like to know everyone’s suggestion for looping through a recordset when you have multiple values you are watching. Here is my example.

    Recordset of (LastName, FirstName, Address, State)

    Smith Joe 111 Main Street GA
    Smith Jim 222 South Street GA
    Jones John 333 West Street FL
    Jones Sue 333 West Street FL
    Jones Bobby 333 West Street FL
    Wall Harry 123 First Street FL
    Wall Marry 123 First Street FL

    Now here is what I would like to do. I want to write the whole recordset to a listbox, but, I want the list to Break on Last Name and I also want to Break if they live at different addresses. This means I need to know when the Last name field changes, as well as when (if) the address changes within the same Last Name. I have seen this done many ways, however, I am interested in the most efficient way of doing it.

    Thanks

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    [pseudocode]
    dim OldLastName as string = last name from first record

    loop
    if OldLastName <> CurrentLastName then
    "break on last name"
    maybe insert a blank line or something like that
    else
    add record to list
    end if
    end loop

    [/pseudocode]
    I don't live here any more.

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Try



    [pseudocode]
    Dim OldName, NewName, OldHouse, NewHouse, OldStreet, NewStreet as String

    For iCount = 1 to RecordsetCount
    Loop through recordset placing relative field values into the declared strings.


    CheckForChange(OldNAme, NewName, OldHouse, NewHouse, OldStreet, NewStreet)

    Next iCount



    private sub CheckForChange(OldName as string, NewName as String, OldHouse as string, NewHouse as String, OldStreet as string, NewStreet as String)

    CompactStrings(oldname, NewName)
    if CompactStrings=False then
    InsertBreak
    Exit sub
    end if
    CompactStrings(oldhouse, NewHouse)
    if CompactStrings=False then
    InsertBreak
    Exit sub
    end if
    CompactStrings(oldStreet, NewStreet)
    if CompactStrings=False then InsertBreak

    end sub


    private function CompactStrings(strOld as String, strNew as String
    ) As Boolean

    strOld=trim(strOld)
    strNew=trim(strNew)
    if strOld<>strNew OR strOld.Length<>strNew.Length then Return False

    end function

    Private Sub InsertBreak
    Code to insert break
    End Sub
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

Posting Permissions

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



Click Here to Expand Forum to Full Width