Posted by : Sudhir Chekuri Thursday, 26 September 2013


vbscript inputbox
inputbox control is used to take some input from the user.
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.


Explanation: Here i have a function named as PasswordBox which takes one input parameter. If you call it message textbox popup will be displayed to take input from user in password format and it returns back. The returned value is printed using echo method in line2 in the below example 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

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Followers

Total Pageviews

Powered by Blogger.

Blog Archive

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -