Solved

name generator

Posted on 2001-08-07
7
158 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 22

Accepted Solution

by:
rspahitz earned 50 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now