PDA

View Full Version : Sleeper: Input Mask



buddy2000
02-11-2011, 02:14 PM
How do I do this input mask. I am close but keep getting syntax error.

The number of places is irrelevant right now. I just need to know how to do this.



Dim x As String
x = InputBox(Title, .Value " # #",)

pike
02-12-2011, 03:26 AM
Hi buddy2000

Close but no Banana


Option Explicit

'// 25 May 2003 //
'// Amended Ivan F Moala

Public Declare Function GetActiveWindow Lib "user32" () As Long

Public 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

Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" ( ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

Public Declare Function SetTimer _
Lib "user32" ( ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

Public Declare Function KillTimer _
Lib "user32" ( ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long

Public Declare Function GetForegroundWindow _
Lib "user32" () As Long

Private Const nIDE As Long = &H100
Private Const EM_SETPASSWORDCHAR = &HCC
Private hdlEditBox As Long
Private Fgrndhdl As Long

Public Function TimerFunc( ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal nEvent As Long, _
ByVal nSecs As Long) As Long
Dim hdlwndAct As Long
'// Do we have a handle to the EditBox
If hdlEditBox > 0 Then Exit Function
'// Get the handle to the ActiveWindow
hdlwndAct = GetActiveWindow()
'/ Get the Editbox handle
hdlEditBox = FindWindowEx(hdlwndAct, 0, "Edit", "")
'/ Set the password character for the InputBox
SendMessage hdlEditBox, EM_SETPASSWORDCHAR, Asc("*"), ByVal 0
End Function

Public Function InPutBoxPwd(fPrompt As String, _
Optional fTitle As String, _
Optional fDefault As String, _
Optional fXpos As Long, _
Optional fYpos As Long, _
Optional fHelpfile As String, _
Optional fContext As Long) As String
Dim sInput As String
'/ Initialize
hdlEditBox = 0
Fgrndhdl = GetForegroundWindow
'/ Windows-Timer
SetTimer Fgrndhdl, nIDE, 100, AddressOf TimerFunc
'/ Main InputBox
If fXpos Then
sInput = InputBox(fPrompt, fTitle, fDefault, fXpos, fYpos, fHelpfile, fContext)
Else
sInput = InputBox(fPrompt, fTitle, fDefault, , , fHelpfile, fContext)
End If
'/ Kill the correct Timer
KillTimer Fgrndhdl, nIDE
'/ Pass result
InPutBoxPwd = sInput
End Function

This is The main routine where we test it

Sub GetPassWord()
Dim x As String
x = InPutBoxPwd("Please enter password", "Sentry")
If x = vbNullString Then
MsgBox "User Cancelled"
Else
MsgBox "User entered " & x
End If
End Sub

mdmackillop
02-14-2011, 06:35 AM
Inputbox just takes a string. I don't believe you can use a mask as in an Access field. You could add a description such as

x = InputBox("Enter data as " & vbCr & "' # #'")

and add code to test and accept/reflect the result.