Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

*ing input box

Status
Not open for further replies.

IanStrange

Programmer
Sep 16, 2002
36
GB
Hi
I am using input boxes as passwords to prevent the use of macros by certain button happy members of staff. I would like for everything that is typed into the input box to be ***** but the actual text to be stored.
Is this possible?
If not how could I acheive the same end?
Thanks for any help.
Ian

No man is an island but 6 tied together make quite a good raft.
 
Set the property PasswordChar of the inputbox to '*'

Diederik
 
It's not easy with an InputBox. Use a TextBox, with it's PasswordChar set to '*', and put it on a small modal form to simulate the Inputbox control.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Sorry to sound dumb but how do I do that here is the code I have got.

Private Sub CommandButton3_Click()
Dim Message, Title, Default, MyValue
Message = "Please enter the thames fruit password"
Title = "Input thames password"
Default = ""
MyValue = InputBox(Message, Title, Default)

If MyValue = "sparrow" Then
Call Snap_Shot
else
msgbox("Incorrect Password")
end if
end sub

No man is an island but 6 tied together make quite a good raft.
 
Ahhh cool got it.
Thanks for the help
Ian

No man is an island but 6 tied together make quite a good raft.
 
As you are in the VB6 forum I assume this is VB6 and not VBA. It's normally good practice to specifically declare variable types as:
Dim strMessage as String

A very simplified version would have a textbox and a command box on a new form called frmPasswd. Form code would be:
[tt]
Option Explicit

Private Sub Command1_Click()
Form1.myvalue = Text1.text
Unload Me
End Sub

Private Sub Form_Load()
Dim strPassWd As String
Text1.PasswordChar = "*"
End Sub
[/tt]

On your form1, dim myvalue as Public, and call the password something like this:
[tt]
Private Sub Command3_Click()
Dim a as Long
For a = 1 To 3
frmPassWd.Show vbModal
If myvalue = "sparrow" Then
'do whatever here
Exit Sub
MsgBox "Try again"
End If
Next
MsgBox "No Access to this function"
End Sub
[/tt]

This is only very skeleton code, and you will need error checking, proper declarations and testing before use in a production environment, but it should get you started.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Or, for a shorter variant of the code in the link posted by rzs0502, try thread222-662729

Generally, I prefer to use the CBT hooking technique, which looks something like this (this code goes in a module):
[tt]
Option Explicit

' Necessary constants for hooking
Private Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5

' Constants for password masking
Public Const EM_SETPASSWORDCHAR = &HCC

' Working variables that require global scope in hooking module
Private hHook As Long

' The API declarations we need
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long


' Our wrapper for the normal MsgBox function
Public Function vbInputBox(Prompt As String, Optional Title As String, Optional Default As String, Optional Xpos As Single, Optional YPos As Single, Optional Helpfile As String, Optional Context As Long) As String 'Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String, Optional HelpFile As String, Optional Context As Long) As Long
hHook = SetWindowsHookEx(WH_CBT, AddressOf CBTProc, App.hInstance, 0)
vbInputBox = InputBox(Prompt, Title, Default, Xpos, YPos, Helpfile, Context)
End Function

' Our wrapper for the normal MsgBox function
Public Function vbMsgBox(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String, Optional Helpfile As String, Optional Context As Long) As Long
hHook = SetWindowsHookEx(WH_CBT, AddressOf CBTProc, App.hInstance, 0)
vbMsgBox = MsgBox(Prompt, Buttons, Title, Helpfile, Context)
End Function

Private Function CBTProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim hwndEditControl As Long

If lMsg = HCBT_ACTIVATE Then
hwndEditControl = FindWindowEx(wParam, 0, "Edit", "") ' get the edit control

' Do your stuff here to modify the window
SendMessage hwndEditControl, EM_SETPASSWORDCHAR, Asc("*"), 0

' Immediately unhook
UnhookWindowsHookEx hHook
End If
CBTProc = False
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top