-
September 8th, 2007, 06:32 AM
#1
[RESOLVED] Modify TextBox PasswordChar value using a Checkbox
Hi All,
I have been trying to add a checkbox which will allow the password in a text box to be masked / unmasked.
I have a text box named:
Text_CSS_Password
and a checkbox named:
Check_CSS_MaskPass
I want the PasswordChar value of the Text_CSS_Password to be set as "#" when the Check_CSS_MaskPass is checked (Value = 1) and to be set as " " (Blank) when Check_CSS_MaskPass is unchecked (Value = 0).
The code i am using is:
Code:
Private Sub Check_CSS_MaskPass_Click()
If Check_CSS_MaskPass.Value = "1" Then Text_CSS_Password.PasswordChar = "#"
If Check_CSS_MaskPass.Value = "0" Then Text_CSS_Password.PasswordChar = " "
End Sub
I have also tried:
Code:
Private Sub Check_CSS_MaskPass_Click()
If Check_CSS_MaskPass.Value = "1" Then Text_CSS_Password.PasswordChar.Value = "#"
If Check_CSS_MaskPass.Value = "0" Then Text_CSS_Password.PasswordChar.Value = " "
End Sub
When i run the program and click the checkbox is get the following error:
Compile Error: Method or data member not found
and the following code is highlighted:
.PasswordChar =
Im quite new to VB but i dont think its far away from the way its supposed to be done?
While we are on the subject, will this method unmask the entire password if the checkbox is clicked half way through entering a password? If not ill have to look at another method.
Any help would be appreciated,
Thanks,
Gareth.
Last edited by GarethD.Norris; September 9th, 2007 at 04:08 AM.
Reason: Problem Solved
-
September 8th, 2007, 08:35 AM
#2
Re: Modify TextBox PasswordChar value using a Checkbox
Text_CSS_Password is a standard VB textbox? Correct?
Where did you get the idea that there is a Text_CSS_Password.PasswordChar.Value property? Being new to VB, strongly recommend you add OPTION EXPLICIT to the top of every code object you create: form, module, class, usercontrol, etc.
Your problem is easy to fix: remove the .Value from Text_CSS_Password.PasswordChar.Value
To unmask the password completely, use a null string, i.e., "" not " ". And yes, it is masked/unmasked as soon as you change the .PasswordChar property.
Last edited by LaVolpe; September 8th, 2007 at 08:40 AM.
Insomnia is a simple byproduct of "it can't be done"
-
September 8th, 2007, 11:49 AM
#3
Re: Modify TextBox PasswordChar value using a Checkbox
Hi Mate,
Thanks for the reply but i think you missed that i have two code sections. In the first code box i did not use the .value at the end of Text_CSS_Password.PasswordChar as shown below:
Code:
Private Sub Check_CSS_MaskPass_Click()
If Check_CSS_MaskPass.Value = "1" Then Text_CSS_Password.PasswordChar = "#"
If Check_CSS_MaskPass.Value = "0" Then Text_CSS_Password.PasswordChar = " "
End Sub
I only used this in the second code section to say that i had tried it (The reason i tried is that Check_CSS_MaskPassword has a .value on the end and works fine.)
Code:
Private Sub Check_CSS_MaskPass_Click()
If Check_CSS_MaskPass.Value = "1" Then Text_CSS_Password.PasswordChar.Value = "#"
If Check_CSS_MaskPass.Value = "0" Then Text_CSS_Password.PasswordChar.Value = " "
End Sub
I changed the " " to "" and added an Option Explicit to the start of each form as you recomended but still no change. You were correct that the Text_CSS_Password is a standard textbox.
The code i am using now is below with the section highlighted by the error in large bold text:
Code:
Private Sub Check_CSS_MaskPass_Click()
If Check_CSS_MaskPass.Value = "1" Then Text_CSS_Password.PasswordChar = "#"
If Check_CSS_MaskPass.Value = "0" Then Text_CSS_Password.PasswordChar = ""
End Sub
Any idea what the problem is?
Thanks,
Gareth.
Last edited by GarethD.Norris; September 8th, 2007 at 12:00 PM.
-
September 8th, 2007, 01:15 PM
#4
Re: Modify TextBox PasswordChar value using a Checkbox
The checkbox values are numerical not string, but that should not be the problem.
You still get a "method or data member not found" error?
If so, add this statement to the top of your click event and let us know what reports back and which version of VB you are using. It will be printed to your debug window (CTRL+G)
Debug.Print TypeName(Text_CSS_Password)
Insomnia is a simple byproduct of "it can't be done"
-
September 8th, 2007, 05:32 PM
#5
Re: Modify TextBox PasswordChar value using a Checkbox
The values are 0,1 and 2, for unchecked, checked and vbGray
Code:
Private Sub Check_CSS_MaskPass_Click()
If Check_CSS_MaskPass.Value = vbChecked Then
Text_CSS_Password.PasswordChar = "*"
Else
Text_CSS_Password.PasswordChar= ""
Endif
End Sub
Last edited by dglienna; September 8th, 2007 at 05:43 PM.
-
September 8th, 2007, 07:06 PM
#6
Re: Modify TextBox PasswordChar value using a Checkbox
LaVolpe: I am using version: 8176 VBA: Retail 6.0.8169. I added the code as you stated and pressed Ctrl+G but noting appeared in the "Immediate" window.
dglienna: I tried your code (Just an IF / EndIF rework of the code i was using) and no change which is to be expected.
What really is odd is that If i just create the textbox and checkbox in a new project and use the exact same code it works perfectly. I have triple checked everything in the main code and it seems fine. As im not far into the project im going to start a new one and copy the code bit by bit to see.
Also the Option Explicit seems to mess up some code im using to launch an Attachmate session so i have removed it for now.
Gareth.
-
September 8th, 2007, 07:23 PM
#7
Re: Modify TextBox PasswordChar value using a Checkbox
you NEED to use Option Explicit in ALL subs, functions, and property code.
your errors are caused by using names that weren't declared (with DIM)
add it everywhere, and correct the errors.
-
September 8th, 2007, 09:49 PM
#8
Re: Modify TextBox PasswordChar value using a Checkbox
As David says, don't remove Option Explicit.
As far as your problem goes, do you have any lines of code like: Dim Text_CSS_Password ? That would explain an error. If not, something else in your project is a bit hosed up, otherwise it would still fail in the new project.
Insomnia is a simple byproduct of "it can't be done"
-
September 9th, 2007, 12:03 AM
#9
Re: Modify TextBox PasswordChar value using a Checkbox
if something else modifies that checkbox, then your event wiil fire when you don't want it to. Step thru the code to see what happens..
Don't! have the click event set the checkbox in the checkbox_click() event. Instant problem! Loop never ends. App will crash in a few seconds.
-
September 9th, 2007, 04:07 AM
#10
Re: Modify TextBox PasswordChar value using a Checkbox
Hi Guys,
I started a new project, drew the form again and copied the code exactly as it was it and now works fine (Without Option Explicit).
I have not used Dim statements in some places but when i looked in VB6 book last night it states:
"Although creating a variable out of thin air in the middle of a procedure is perfectivly acceptable, this is not considered good programming practice. A better programming practice is to declare your variables at the beginning of each event procedure."
So that should not have been the problem but i will include them in future.
Reading a little further into the same book has shown me (At least i think) why the Option Explicit causes the error and i will try to sort the exisiting instances before moving forward with the code.
Thanks for your help guys, the original problem is now resolved so i will update the first post now.
Gareth
-
September 9th, 2007, 05:48 AM
#11
Re: Modify TextBox PasswordChar value using a Checkbox
Hi Guys,
Just an update to say that i have now declaired all the variables and have readded the Option Explicit with all code now functioning correctly. I am also using this oppertuinity to add comments to all my code before it gets too big as this was also discussed in the book i have.
Thanks,
Gareth.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|