473,805 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How Do I run this code by dbl clicking a field in a form.

8 New Member
I am trying to run this code in a form when a user double clicks in a particular field. I am unsure how I should do it since it uses 2 text files, one to generate and the other to store to eleminate redundancy. If you can help this newbie, thanks.
Expand|Select|Wrap|Line Numbers
  1. '==========================================================================
  2. '
  3. ' NAME: RandomPasswordGenerator.vbs
  4. '
  5. ' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
  6. ' URL: http://www.thespidersparlor.com
  7. ' DATE  : 7/29/2004
  8. ' Modified by Homer Simpson, 9/05/2007 for Wire Room Pin generation
  9. '
  10. ' COMMENT: Generates Random Passwords meeting "Complex" Requirements
  11. '          By default will generate a 4 digit password.
  12. '          Edit line passLen = 4 to change length
  13. '==========================================================================
  14. Option Explicit
  15. 'On Error Resume Next
  16.  
  17. Dim BankCode, newpass, passList, inFlag, pgLength, x, fso, ts, passLen, WshShell, passin 
  18. Const ForWriting = 2, ForAppending = 8, ForReading = 1
  19. passLen = 4
  20.  
  21. 'Give inFlag (input Flag) an initial value to ensure we run once
  22. inFlag = "invalid"
  23.  
  24. Do While inFlag = "invalid"
  25.     BankCode = InputBox("Enter a valid Bank Code")
  26.  
  27.     'Quit if no entry
  28.     If BankCode = "" Then WScript.Quit
  29.     BankCode=UCase(BankCode)    
  30.     'copy this line per bank. Put codes in upper case
  31.     If (BankCode = "BW") or (BankCode = "BWE") then inFlag = "valid"
  32.      If (BankCode = "CB") or (BankCode = "CBE") then inFlag = "valid"
  33.       If (BankCode = "FB") or (BankCode = "FBE") then inFlag = "valid"
  34.        If (BankCode = "MB") or (BankCode = "MBE") then inFlag = "valid"
  35.         If (BankCode = "MM") or (BankCode = "MME") then inFlag = "valid"
  36.          If (BankCode = "ON") or (BankCode = "ONE") then inFlag = "valid"
  37. Loop
  38.  
  39.  
  40. 'Generate the PIN
  41. inFlag= "invalid"
  42. Do While inFlag = "invalid"
  43.     set ts = nothing
  44.     set fso = nothing
  45.     Set fso = CreateObject("Scripting.FileSystemObject")
  46.     Set ts = fso.OpenTextFile ("PasswordList.txt", ForReading)
  47.     newpass = generatePassword(passLen)
  48.     newpass = BankCode + newpass
  49.  
  50.     ' validate password uniqueness
  51.  
  52.     inflag="valid"
  53.     Do While ts.AtEndOfStream <> true
  54.         passin=ts.ReadLine
  55.         if passin = newpass then inFlag="invalid"
  56.     Loop
  57. Loop
  58. set ts = nothing
  59. set fso = nothing
  60.  
  61. 'Now save it all to a text file.
  62. passList = newpass & vbCrLf
  63. Set fso = CreateObject("Scripting.FileSystemObject")
  64. Set ts = fso.CreateTextFile ("NewPin.txt", ForWriting)
  65. ts.write passList
  66.  
  67. set ts = nothing
  68. set fso = nothing
  69.  
  70. 'Open PIN in notepad
  71. set WshShell = WScript.CreateObject("WScript.Shell")
  72.  
  73. 'Launch Notepad from the command line 
  74. WshShell.Run "Notepad.exe NewPin.txt"
  75.  
  76. 'Write Password to permanent list
  77. Set fso = CreateObject("Scripting.FileSystemObject")
  78. Set ts = fso.OpenTextFile ("PasswordList.txt", ForAppending)
  79. ts.write passList
  80.  
  81. set ts = nothing
  82. set fso = nothing
  83.  
  84. 'end of program
  85.  
  86. Function generatePassword(PASSWORD_LENGTH)
  87.  
  88. Dim NUMLOWER, NUMUPPER 
  89. Dim newPassword, count, pwd
  90.  
  91.  NUMLOWER    = 48  ' 48 = 0
  92.  NUMUPPER    = 57  ' 57 = 9
  93.  
  94.  ' initialize the random number generator
  95.  Randomize()
  96.  
  97.  newPassword = ""
  98.  count = 0
  99.  DO UNTIL count = PASSWORD_LENGTH
  100.  
  101.        pwd = Int( ( NUMUPPER - NUMLOWER + 1 ) * Rnd + NUMLOWER )
  102.  
  103.   newPassword = newPassword + Chr( pwd )
  104.  
  105.   count = count + 1
  106.  
  107.  Loop
  108.  
  109. 'The password is good so return it
  110.  generatePassword = newPassword
  111. End Function
Sep 6 '07 #1
1 1580
Scott Price
1,384 Recognized Expert Top Contributor
It looks to me like you have two separate and independent functions doing the same thing here. Did you write these?

If you are only trying to generate a random password by double-clicking, you should be able to use the second function (starting with line 86 of your code), you'll need to pass it the length, but in the double click event of your text box, write this kind of code:

Expand|Select|Wrap|Line Numbers
  1. Call generatePassword(6)
This code will pass the password length of 6 characters.

The generatePasswor d function will, of course, go into a standard code module as a Public Function.

From what I can tell just looking at this, the first function you have is a highly specific password generator possibly for a banking institution?

Regards,
Scott
Sep 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2726
by: Pat Scott | last post by:
I am looking for a general purpose javascript snippet that enables me to <div> or <span> HTML to make portions of the form be hidden and then appear. The form contains about 12 sections and some sections can contain subsections. When the user clicks on a checkbox, I want previously hidden text boxes, radio buttons, text, drop down menus, and additional checkboxes to appear. In some cases, clicking on a checkbox in a section can cause...
2
3356
by: Dutchy | last post by:
Hi there, After spending several hours trying all I could imagine and search for in Google I gave up. In a continuous form I want to sort the choosen column by clicking the header (label) of that column. I even want to sort up and down if one clicks again on the same header. No problem so far, all works well for one column. Now I want to sort on the first choosen column ASC or DESC and additionally on a second column ASC. I use the...
1
1644
by: Heather Crow | last post by:
I have a VS.NET 2003 Visual Basic form which keeps hanging. It does not appear to matter what textbox I am on. When trying to edit the field I cannot move focus from this field to another. Clicking buttons etc. does nothing and the focus remains with the field I had been editing. The text boxes are bound to a record in a SQL database.
1
10307
by: DoctorV3774 | last post by:
We developed a small test database that we are using to attempt to connect to a wsdl to consume web services. The database form contains 3 fields and a submit button on the form. At the bottom I've included the code behind the button on the form and the class module code that was generated by the Web Service Tool. I've added a little bit of information that pertains to the Access Database and our process and expected results: VBA for...
0
1178
by: sklett | last post by:
I've got a odd thing happening when tabbing through my form. everything is fine as long as I only tab through the fields, but if I skip 10 fields and click in a field, enter data then hit tab it will just to the control AFTER the last control I TABBED to. This doesn't make sense to me. Does a form keep track of tab index? Do I need to set this index somewhere when clicking on a field? Thanks for any help!
5
2006
by: LANTEK | last post by:
I am currently working on a form that would have multiple fields plus an upload file spot. I cannot add the code for the upload file. Also, after clicking submit the form should send an email to the specified email address and currently those emails are not being recieved. All that happens is the php code box ocomes up and lets the user know that the form has been submitted and doesn't re-direct to the thank you page..Please help Here is my...
6
4934
by: Paul Furman | last post by:
I'm getting incorrect response when hitting the enter key instead of actually clicking the button on a form. It activates but the post data isn't being sent I think. The php generated page flickers & reloads but doesn't perform the update. This is php generated, I'm just pasting the page source (reformatted & extra junk removed and I think they are now identical), and it's running on my localhost apache server for testing so maybe...
16
3558
by: google | last post by:
In a continuous form the following code is under a button in the form header. In Access 2003 and earlier, this goes to a new record, then adds relevant data to that new record. DoCmd.GoToRecord , , A_NEWREC If <some codeThen = "CA002" Else
6
4516
by: ljstern | last post by:
Hello. I am using MS Access 2003 with XP/pro. I have a form that has the following properties set through the property sheet: form: AllowAdditions = False CartridgeID field: Locked = True The AllowAdditions property is set so that the user can navigate through the records but not be able to begin a new record without clicking the New Record button. The ID field is locked so the user cannot change that field, while still being able to...
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10613
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.