Results 1 to 4 of 4

Thread: Pulling street based on city provided from a list?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Posts
    360

    Pulling street based on city provided from a list?

    I don't know what you would call it but I want to do something like this:

    I have a list that contains the following and will have more in the future.

    {buffalo}
    street
    street2
    street3
    {end}
    {albany}
    street1
    street2
    street3
    street4
    {end}

    Now I want to create a function where I can pull a random street from the city I call, for example:

    msgbox PullStreet(albany)

    and the above might return "street3"

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Pulling street based on city provided from a list?

    Code:
    Private Type CitiesAndStreets
        City As String
        street As String
    End Type
    Private CAS() As CitiesAndStreets
    Private Sub Form_Load()
    
        Dim intIndex As Integer
        
        Randomize
        ReDim CAS(0)
        ' You could do this in a loop while reading a file containing the data
        CAS(UBound(CAS)).City = "buffalo"
        CAS(UBound(CAS)).street = "street"
        ReDim Preserve CAS(UBound(CAS) + 1)
        
        CAS(UBound(CAS)).City = "buffalo"
        CAS(UBound(CAS)).street = "street1"
        ReDim Preserve CAS(UBound(CAS) + 1)
        
        CAS(UBound(CAS)).City = "buffalo"
        CAS(UBound(CAS)).street = "street2"
        ReDim Preserve CAS(UBound(CAS) + 1)
        
        CAS(UBound(CAS)).City = "Albany"
        CAS(UBound(CAS)).street = "street1"
        ReDim Preserve CAS(UBound(CAS) + 1)
        
        CAS(UBound(CAS)).City = "Albany"
        CAS(UBound(CAS)).street = "street2"
        ReDim Preserve CAS(UBound(CAS) + 1)
        
        CAS(UBound(CAS)).City = "Albany"
        CAS(UBound(CAS)).street = "street3"
        ReDim Preserve CAS(UBound(CAS) + 1)
        
        CAS(UBound(CAS)).City = "Albany"
        CAS(UBound(CAS)).street = "street3"
        ReDim Preserve CAS(UBound(CAS) + 1)
        
        Do
            intIndex = Int((UBound(CAS) + 1) * Rnd)
            If CAS(intIndex).City = "Albany" Then
                MsgBox CAS(intIndex).street
                Exit Do
            End If
            
        Loop

  3. #3
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Pulling street based on city provided from a list?

    thud

    Seems that several steps could do the trick..

    First, use a loop to store the relevant streets in an array
    1. Loop thru the list to find the city.
    2. Continue the loop, adding items to an array (this will be streets)
    3. When next city (or end) is encountered, exit the loop

    Second, randomly pick a street from that array.

    Does that get you started?

    EDIT: Dang, Marty was quicker to the punch than I was
    EDIT-2: Not to mention -- somewhat more specific

    Spoo
    Last edited by Spoo; May 9th, 2009 at 02:12 PM. Reason: Marty

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Pulling street based on city provided from a list?

    Can I call shenanigans? Are you doing this in VB6 (this thread) or in .NET (as in this thread? http://www.vbforums.com/showthread.php?t=568696 ) ???

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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