473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Visual Basic Tip of the Week #3

8,435 Expert 8TB
Originally posted by sashi

Generate Random Password

Expand|Select|Wrap|Line Numbers
  1. ' Form code - frmPasswordGenerate
  2.  
  3. Private Declare Function GetTickCount Lib "kernel32" () As Long
  4.  
  5. Public Function PassGen(nLen As Long) As String
  6.   Dim range As Collection
  7.   Dim ivalue As Long, icount As Long, iLen As Long
  8.   Dim pass As String
  9.  
  10.   Set range = New Collection
  11.   range.Add ("0")
  12.   range.Add ("1")
  13.   range.Add ("2")
  14.   range.Add ("3")
  15.   range.Add ("4")
  16.   range.Add ("5")
  17.   range.Add ("6")
  18.   range.Add ("7")
  19.   range.Add ("8")
  20.   range.Add ("9")
  21.  
  22.   iLen = range.Count
  23.  
  24.   Do Until icount = nLen
  25.     Randomize
  26.     ivalue = CByte(Mid(CStr(Rnd(GetTickCount)), 3, 2))
  27.     If ivalue > 0 And ivalue <= iLen Then
  28.       icount = icount + 1
  29.       pass = pass & range(ivalue)
  30.     End If
  31.   Loop
  32.  
  33.   PassGen = pass
  34. End Function
  35.  
  36. Private Sub cmdGeneratePassword_Click()
  37.   MsgBox PassGen(8)
  38. End Sub
Apr 25 '07 #1
0 968

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: John Timbers | last post by:
I'd like to purchase Visual C# .Net for learning purposes only since it's a lot cheaper than Visual Studio (note that I'm a very experienced C++ developer). Can someone simply clarify the basic...
34
by: John Timbers | last post by:
I'd like to purchase Visual C# .Net for learning purposes only since it's a lot cheaper than Visual Studio (note that I'm a very experienced C++ developer). Can someone simply clarify the basic...
3
by: Frank van der Kleij | last post by:
I want to make een marco in visual Basic that: can look at a range and can check, in every cel in that range, if it is equal as 1 en than change the text color to yellow. I am searching for a...
3
by: Jay Patel | last post by:
Hello, I need to write visual basic.net code to interface with a Mettler Toledo Shipping Scale that interfaces with a PC via USB or a serial port. I have seen example code on how to communicate...
8
by: Chris Asaipillai | last post by:
Hi there I have some questions for those experienced Visual Basic 6 programmers out there who have made the transition from VB6 to Vb.net. How long did it take you to learn at least the basic...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.