Solved

name generator

Posted on 2001-08-07
7
161 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

791 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