Results 1 to 3 of 3

Thread: Generating Words Using Two Lists

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Generating Words Using Two Lists

    Ok i have two lists on my form that both have wordlists in them. I want to do two things, using the neatest and quickest code possible.

    First

    It will go down list 1 using the first word, and go down list 2 using the first word and merge them together and add them to list 3.

    So if list1 was

    Richard
    Stephen
    Shane

    and list 2 was

    Love
    Simple
    Clever

    i would get the following

    RichardLove
    StephenSimple
    ShaneClever

    Second

    It will go down list 1 using the first word, and go down list 2 using all the words and merge them together and add them to list 3.

    So if list1 was

    Richard
    Stephen
    Shane

    and list 2 was

    Love
    Simple
    Clever

    i would get the following

    RichardLove
    RichardSimple
    RichardClever
    StephenLove
    StephenSimple
    StephenClever
    ShaneLove
    ShaneSimple
    ShaneClever

    Hope this is clear and all help appreciated.

    Regards
    Im Learning !!!!

  2. #2
    Member
    Join Date
    Dec 2006
    Posts
    53

    Re: Generating Words Using Two Lists

    This will make list3 like your FIRST example, and list4 like your SECOND example..

    VB Code:
    1. Dim I As Integer
    2.   Dim J As Integer
    3.  
    4.   For I = 0 To List1.ListCount - 1
    5.     If (List2.ListCount > I) Then list3.AddItem List1.List(I) & List2.List(I)
    6.     For J = 0 To List2.ListCount - 1
    7.       list4.AddItem List1.List(I) & List2.List(J)
    8.     Next J
    9.   Next I
    Help me win cash, vote for my code: Random Quotes - Setting / Retrieving Cookies

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Generating Words Using Two Lists

    Here is a link on how to create a cartesian join of the lists, or list all possible combinations.

    http://www.vbforums.com/showthread.p...73#post2706273

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