VBScript Issue w/ IE Object Displaying w/ focus - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

VBScript Issue w/ IE Object Displaying w/ focus

rdutilrdutil Posts: 1Member
I'm not sure if I'm in the correct forum or not, but I thought I
would give it a shot to see if someone can offer up some type of solution. Let me preface this by saying that I am not very experienced at VBScript. I've been trying to piece this together this small program from some examples.

I'm trying to create a small desktop application using VBScript to present a menu to the user, allow selection of options 1-7, and then upload a file (based on user selection) via FTP to a host server.

Within this VBScript program, I'm trying to create a function that will create an IE window object that will display an HTML formatted menu with those 7 options. There is a input box for the user to enter a single option 1 - 7. I will then return the value that was entered by the user.

The script I currently have will create the IE object, but the window does not have focus and will not display on top of any other open applications. I am working on Windows XP. I've seen this problem discussed on some other forums. I've tried some suggestions that I've seen on some forums, but to no avail. Does anyone have any tricks that will help me display this IE window with focus on top any other open apps? We are soon upgrading to Windows 7. Will that make and difference?

Any advice is much appreciated. I had a suggestion today that I try an
additional piece of software called Z-Mover that will run in the background and pre-position any applications that open up. But, I am hoping that I can do this without the additional software. My code is listed below. Thanks in advance for any suggestions.

My Code:

'-----------------------------------------------------------------------------
-
Function GetUserInput()
' This function uses Internet Explorer to
' create a dialog and prompt for user input.
'
' Argument: [string] prompt text, e.g. "Please enter your name:"
' Returns: [string] the user input typed in the dialog screen
'
Dim objIE
Dim UserPromptTable

userPromptTable = " " _
& " " _
& " " _
& " " _
& " " _
& " " _
& " " _
& " " _
& " " _
& "

Please select payroll upload option:

HOURLY:1.)Company 1
2.)Company 2
3.)Company 3
4.)Company 4
ADMIN:5.)Company 5
6.)Company 6
7.)Company 7
"

' Create an IE object
Set objIE = CreateObject( "InternetExplorer.Application" )


' Specify some of the IE window's settings
objIE.Navigate "about:blank"
objIE.Document.Title = "Input required " & String( 50, "." )
objIE.ToolBar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 360
objIE.Height = 360

' Center the dialog window on the screen
With objIE.Document.ParentWindow.Screen
objIE.Left = (.AvailWidth - objIE.Width ) 2
objIE.Top = (.Availheight - objIE.Height) 2
End With

' Wait till IE is ready
Do While objIE.Busy
WScript.Sleep 200
Loop
' Insert the HTML code to prompt for user input
objIE.Document.Body.InnerHTML = "

" &
userPromptTable _
& "

" & vbCrLf _
& "

" & vbCrLf _
& "

" _
& "

"
' Hide the scrollbars
objIE.Document.Body.Style.overflow = "auto"
' Make the window visible
objIE.Visible = 1
' Set focus on input field
objIE.Document.All.UserInput.Focus
objShell.AppActivate objIE

' Wait till the OK button has been clicked
On Error Resume Next
Do While objIE.Document.All.OK.Value = 0
WScript.Sleep 200
' Error handling code by Denis St-Pierre
If Err Then ' user clicked red X (or alt-F4) to close IE window
IELogin = Array( "", "" )
objIE.Quit
Set objIE = Nothing
Exit Function
End if
Loop
On Error Goto 0

' Read the user input from the dialog window
GetUserInput = objIE.Document.All.UserInput.Value

' Close and release the object
objIE.Quit
Set objIE = Nothing
End Function

Sign In or Register to comment.