- Back to Home »
- vbscript »
- vbscript inputbox control (cannot mask text inside it like password texboxt)
Posted by :
Sudhir Chekuri
Thursday, 26 September 2013
vbscript inputbox |
It comes with a textbox and two buttons(ok and cancel)
vbscript code to take text from user from inputbox and displaying it in message box
strUser=Inputbox("Enter Username")
msgbox strUser
So in the above code strUser variable is used to store value entered in inputbox.
msgbox is used to display value present in the variable.
This vbscript inputbox cannot work like password box by masking text inside it.
But it is possible to mask inputbox text like password if you use IE object using the below code.
VBScript code to mask text inside it like password textbox
Dim bPasswordBoxWait ' A required global variable
wsh.echo "You entered:", PasswordBox("Enter your password")
Function PasswordBox(sTitle)
set oIE = CreateObject("InternetExplorer.Application")
With oIE
.FullScreen = True
.ToolBar = False : .RegisterAsDropTarget = False
.StatusBar = False : .Navigate("about:blank")
While .Busy : WScript.Sleep 100 : Wend
With .document
With .ParentWindow
.resizeto 400,100
.moveto .screen.width/2-200, .screen.height/2-50
End With
.WriteLn("<html><body bgColor=Silver><center>")
.WriteLn("[b]" & sTitle & "[b]")
.WriteLn("Password <input type=password id=pass> " & _
"<button id=but0>Submit</button>")
.WriteLn("</center></body></html>")
With .ParentWindow.document.body
.scroll="no"
.style.borderStyle = "outset"
.style.borderWidth = "3px"
End With
.all.but0.onclick = getref("PasswordBox_Submit")
.all.pass.focus
oIE.Visible = True
bPasswordBoxOkay = False : bPasswordBoxWait = True
On Error Resume Next
While bPasswordBoxWait
WScript.Sleep 100
if oIE.Visible Then bPasswordBoxWait = bPasswordBoxWait
if Err Then bPasswordBoxWait = False
Wend
PasswordBox = .all.pass.value
End With ' document
.Visible = False
End With ' IE
End Function
Sub PasswordBox_Submit()
bPasswordBoxWait = False
End Sub