[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

name generator

Posted on 2001-08-07
7
Medium Priority
?
167 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
Independent Software Vendors: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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