Results 1 to 6 of 6

Thread: Getting Names from a dictionary

  1. #1
    Guest

    Question

    Hello all,

    i was just making a program to randomly create funny names for players in a game where the npc's are always named different. i got some dictionaries, but i don't have any idea about the code. any and all help would be appreciated.


  2. #2
    Guest
    Here is the code to randomize a list of names:

    Code:
    Private Sub Command1_Click()
    Randomize
    iName = Int((5 * Rnd) + 1)
    If iName = 1 Then iReturn = "Name1"
    If iName = 2 Then iReturn = "Name2"
    If iName = 3 Then iReturn = "Name3"
    If iName = 4 Then iReturn = "Name4"
    If iName = 5 Then iReturn = "Name5"
    
    iName = iReturn
    Msgbox iName
    End Sub
    Hope that helps.

  3. #3
    Guest

    Unhappy ok,

    hey,

    that was fast!

    but anyway, thanks for the help, but im looking for more of a reading a dictionary .txt file instead of having to enter them in there manually. is there any way that exists that i could do that?


  4. #4
    Guest
    Well, if it's in a text file, than you can load them all into a listbox and randomize them from there.

    Code:
    Open "C:\names.txt" For Input As #1
    List1.AddItem Input$(LOF(1), 1)
    Close #1
    And to randomly choose a name on the list:

    Code:
    Function randomnumber(finished)
    Randomize
    randomnumber = Int((Val(finished) * Rnd) + 1)
    End Function
    
    Private Sub Command1_Click()
    On Error Resume Next
    i = randomnumber(List1.ListCount)
    List1.ListIndex = i
    End Sub

  5. #5
    Guest
    ok,

    thanks, but i just need some help on finding the 'listbox' button.


  6. #6
    Guest
    Ok, if you have vb6, open it, create a standard exe, and look to the left for a toolbar. Drag your mouse over the items and it will tell you what they are. Double Click CommandButton and ListBox. And you should be able to continue with the code I gave.

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