Solved

name generator

Posted on 2001-08-07
7
159 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Window placement 17 75
VBA open file from excel cell 4 36
Prevent checkbox click event occur while editing it in vb6 8 34
Excel Automation VBA 19 38
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

896 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

13 Experts available now in Live!

Get 1:1 Help Now