Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How give the focus to a InputBox ?

1,029 views
Skip to first unread message

Yvan

unread,
Oct 28, 2003, 8:11:30 AM10/28/03
to
Hi all,

My question is : how give the focus to a InputBox

Here the script


'*****************************
passwordbox()
InputBox ("nom")

Function PasswordBox()
set oIE = CreateObject("InternetExplorer.Application")
With oIE
.RegisterAsDropTarget = False
.Resizable = False : .FullScreen = True
.width = 400 : .height = 100
.Navigate "about:blank"
Do Until .ReadyState = 4 : WScript.Sleep 100 : Loop
.document.open
.document.write _
"<html><head><" & "script>bboxwait=true;</" _
& "script><title>Password _</title></head>"_
& "<body bgColor=Silver scroll=no" _
& " style='border-Style:outset;border-" _
& "Width:3px'>" _
& "<center><b>Mot de passe : </b>" _
& "<input type=password id=pass><p>" _
& "<button onclick='bboxwait=false;'>" _
& " Valider </button>" _
& "</center></body></html>"
.document.close
Do Until .ReadyState = 4 : WScript.Sleep 100 : Loop
.Visible = True
CreateObject("Wscript.Shell").Appactivate "Password _"
With .document
oIE.left = .parentWindow.screen.width \ 2 - 200
oIE.top = .parentWindow.screen.height\ 2 - 100
.all.pass.focus
PasswordBox = "CANCELLED"
On Error Resume Next
Do While .parentWindow.bBoxWait
if Err Then Exit Function
WScript.Sleep 500
Loop
oIE.Visible = false
PasswordBox = .all.pass.value
End With ' document
End With ' IE
End Function


'*****************************


Thank's in advance for your help.

Yvan


TDM

unread,
Oct 28, 2003, 12:53:03 PM10/28/03
to

Not sure if this is the best way but I did a function call for the onload
event
of the page to do :

this.document.FormName.InputBoxName.focus()

TDM

"Yvan" <yvan....@wanadoo.fr> wrote in message
news:uhSqCUVn...@tk2msftngp13.phx.gbl...

Tom Lavedas

unread,
Oct 28, 2003, 7:56:01 PM10/28/03
to
Actually, there already is a focus in the referenced routine. (I know,
I wrote it. ;-) The problem is to get the IE.App window to have the
desktop focus. That is generally done with the Wscript.Shell
AppActivate method, as in ...

'...


oIE.top = .parentWindow.screen.height\ 2 - 100

CreateObject("Wscript.Shell").AppActivate "Password _"
.all.pass.focus
PasswordBox = "CANCELLED"
'...

I have included that in most of my later examples of this routine.

Tom Lavedas
===========

Yvan

unread,
Oct 29, 2003, 2:12:23 PM10/29/03
to
Thank you for the passwordbox script. It's a great script.

Your answer don't give me the response.

How can i retrieve the focus for the vbscript inputbox after the function
passwordbox ?

--


Salutations

Yves HEILIG

"Tom Lavedas" <lav...@pressroom.com> a écrit dans le message de
news:DaKdnXP5BJ9...@fcc.net...

Torgeir Bakken (MVP)

unread,
Oct 29, 2003, 2:43:01 PM10/29/03
to
Yvan wrote:

> Thank you for the passwordbox script. It's a great script.
>
> Your answer don't give me the response.
>
> How can i retrieve the focus for the vbscript inputbox after the function
> passwordbox ?

Hi

Put a "unique" title on your InputBox, like this:

InputBox "nom", "My unique title"

Create a second script (AppactivateInputBox.vbs below) that you launch just
before you make the callout to the InputBox function that runs AppActivate on
your unique title.

First script:

' ***************************************
passwordbox()
sExternalAppactivateVbs = "some path\AppactivateInputBox.vbs"
CreateObject("Wscript.Shell").Run "wscript.exe " & sExternalAppactivateVbs
InputBox "nom", "My unique title"

(snip)
' ***************************************

Second script AppactivateInputBox.vbs:

' ***************************************
Set oShell = CreateObject("Wscript.Shell")

Do
WScript.Sleep 200
i = i + 1
' give up after 5 seconds if necessary
If i = 25 Then Exit Do
Loop Until oShell.Appactivate("My unique title")
' ***************************************


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


Yvan

unread,
Oct 30, 2003, 8:47:53 AM10/30/03
to
Very fine it work. Great idea !!!

Thank you very much.

--


Salutations

Yves HEILIG

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> a écrit dans le
message de news:3FA01845...@hydro.com...

0 new messages