?
Solved

name generator

Posted on 2001-08-07
7
Medium Priority
?
165 Views
Last Modified: 2010-05-02
ive seen random name generators that uses names from a text file to generate a name and would like to know if i could get some help on starting a project like that
0
Comment
Question by:440
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 6361549
1) Create a database of names (even if the DB is a simple text file)

2) Determine how many records (lines/names) are in your database.

3) Randomly pick an index number to the record: rnd*reccount

4) Locate the entry in the database using the index and pull out the name

0
 

Author Comment

by:440
ID: 6361585
im would need more help with that i dont know alot about programing so im kinda looking for some starter code to get me started i would like to be able to use a txt file for the names just for ease of updating i dont know how to pick a random line in the txt file to display it if you could show me how to get a random line from a txt file and display that line in a label would help more thank you
0
 

Author Comment

by:440
ID: 6361626
im would need more help with that i dont know alot about programing so im kinda looking for some starter code to get me started i would like to be able to use a txt file for the names just for ease of updating i dont know how to pick a random line in the txt file to display it if you could show me how to get a random line from a txt file and display that line in a label would help more thank you
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Accepted Solution

by:
rspahitz earned 200 total points
ID: 6361784
Assuming:

* You start a new VB project and pick a standard EXE
* On the form, add a command button named Command1
* Your textfile is called namelist.txt
* You click the button to generate a random name from the list

Add the following code:

Private Sub Command1_Click
  Dim RecCount as integer
  Dim RecIndex as integer
  Dim PswdName as string

  Randomize Timer

  RecCount = GetRecCount()
  RecIndex = Rnd * RecCount
  PswdName = GetRecName(RecIndex)
  msgbox "Your new password is " & PswdName, vbOKOnly or vbInformation
End Sub

Private Function GetRecCount()
  Dim RecCount as integer
  Dim DummyString as string

  RecCount = 0

  Open "namelist.txt" for input as #1
  while not(eof(1))
    Line Input #1, DummyString
    RecCount = RecCount + 1
  wend
  close #1

  GetRecCount = RecCount
End Function

Private Function GetRecName(Index as integer)
  Dim iCntr as integer
  Dim PswdName as string

  open "namelist.txt for input as #1
  for iCntr=1 to Index
    if eof(1) then
      PswdName = "Error"
    else
      Line Input #1, PswdName
    endif
  next iCntr

  GetRecName = PswdName
End Function

--
I haven't tried this, but it should be really close.
0
 

Author Comment

by:440
ID: 6362018
thats what i was looking for thank you
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6362050
Glad to help.  Did it work without a hitch?  (It's tough to write bug-free code without at least compiling it!)
0
 

Author Comment

by:440
ID: 6362758
yes all i did was put on error resume next in this function
Private Function GetRecCount() because the first time you clicked the button it worked but the second time you  would get a file already open error
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question