mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 IE form to VBScript

Author Message
jeh332

  • Total Posts : 8
  • Scores: 0
  • Reward points : 0
  • Joined: 1/25/2008
  • Status: offline
IE form to VBScript Friday, January 25, 2008 5:04 AM (permalink)
0
So I have a script created that loads a html form in IE.  User should then be able to complete the form and hit the submit button to close IE and pass values back to the script.  At this point the script runs but does not wait for a button click.  The script loads the IE form and closes it before a button click.  Here is my code.
 
HTML Form code:
  <html>
 <head>
 <body>
 <script language="VBScript">
 <!--
 Dim ready = false
 Public TheForm
  Sub Button1_onClick
   ready = true
  End Sub
  Sub window_onLoad ()
   ready = false
  End Sub
  Public Function CheckVal ()
   CheckVal = ready
  End Function
 </script>
 <form name="ValidForm">
  <p>
  <input type="checkbox" name="serviceArea" value="1" CHECKED>Service Area &nbsp;<br>
  <input type="checkbox" name="actors" value="1" CHECKED>Actors &nbsp;<br>
  <input type="checkbox" name="tools" value="1" CHECKED>Tools &nbsp;<br>
  <input type="checkbox" name="preActivities" value="1" CHECKED>Pre-Activities &nbsp;<br>
  <input type="checkbox" name="postActivities" value="1" CHECKED>Post-Activies &nbsp;<br>
  <input type="checkbox" name="goal" value="1" CHECKED>Goal &nbsp;<br>
  <input type="checkbox" name="description" value="1" CHECKED>Description &nbsp;<br>
  <input type="button" name="Button1" value="OK">
  </p>
 </form>
 </body>
 </html>
 

 
VBScript code:
 
   Dim oIE
   Dim Title 
   Dim checkServiceArea, checkActors, checkTools, checkGoal, checkDescription, checkPreActivities, checkPostActivities
   
   
   'Launch Internet Explorer
   Set oIE = CreateObject("InternetExplorer.Application")
     oIE.left=50             ' window position
     oIE.top = 100           ' and other properties
     oIE.height = 380
     oIE.width = 450
     oIE.menubar = 0         ' no menu
     oIE.toolbar = 0
     oIE.statusbar = 0
     oIE.navigate path + "C:\Program Files\Metis\Metis6.0\xml\http\xml.bah.com\xml\scripting\esartoword.htm"  ' Form
     oIE.visible = 1
   
   ' Wait till MSIE is ready
     Do While (oIE.Busy)      
     Loop
      
   ' Wait till the user clicks the OK button
    On Error Resume Next  
    Do  ' Wait till OK button is clicked
    Loop While (oIE.Document.script.CheckVal=false)
    
   ' User has clicked the OK button, retrieve the values
    checkServiceArea = oIE.Document.ValidForm.serviceArea.Value
    checkActors = oIE.Document.ValidForm.actors.Value
    checkTools = oIE.Document.ValidForm.tools.Value
    checkGoal = oIE.Document.ValidForm.goal.Value
    checkDescription = oIE.Document.ValidForm.description.Value
    checkPreActivities = oIE.Document.ValidForm.preActivities.Value
    checkPostActivities = oIE.Document.ValidForm.postActivities.Value
    
    oIE.Quit()             ' close Internet Explorer
    Set oIE = Nothing      ' reset object variable 
   'End
 

#1
    dm_4ever

    • Total Posts : 3673
    • Scores: 82
    • Reward points : 0
    • Joined: 6/29/2006
    • Location: Orange County, California
    • Status: offline
    RE: IE form to VBScript Friday, January 25, 2008 5:34 AM (permalink)
    0
    Look at this example from Tom Lavedas

    http://members.cox.net/tglbatch/wsh/PasswordBox.vbs.txt
     ' Just an example of how to use the function
     '
     wsh.echo "You entered: ", _
              Join(PasswordBox("Enter UID and password", _
                   "Testing"), ", ")
     
     ' A function to present a Password dialog in a VBS (WSF) 
     ' script
     ' Requires WScript version 5.1+
     ' Tom Lavedas <tlavedas@hotmail.com>
     ' with help from and thanks to Joe Ernest and 
     ' Michael Harris
     '
     ' modified 1/2008 to handle IE7
     '
     Function PasswordBox(sPrompt, sDefault)
       set oIE = CreateObject("InternetExplorer.Application")
       With oIE
     ' Configure the IE window
         .RegisterAsDropTarget = False
         .statusbar = false : .toolbar    = false
         .menubar   = false : .addressbar = false
         .Resizable = False 
         .Navigate "about:blank"
         Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop
     ' Test for IE 7 - cannot remove 'chrome' in that version
         sVersion  = .document.parentWindow.navigator.appVersion  
         if instr(sVersion, "MSIE 7.0") = 0 Then .FullScreen = True 
         .width = 400       : .height = 270
     ' Create the password box document
         With .document
           oIE.left = .parentWindow.screen.width \ 2 - 200
           oIE.top  = .parentWindow.screen.height\ 2 - 100
           .open
           .write "<html><head><" & "script>bboxwait=true;</" _
                & "script><title>Password _</title></head>"_
                & "<body bgColor=silver scroll=no " _
                & "language=vbs style='border-" _ 
                & "style:outset;border-Width:3px'" _
                & " onHelp='window.event.returnvalue=false" _
                & ":window.event.cancelbubble=true'" _
                & " oncontextmenu=" _ 
                & "'window.event.returnvalue=false" _
                & ":window.event.cancelbubble=true'" _
                & " onkeydown='if ((window.event.keycode>111)"_
                & " and  (window.event.keycode<117)) or" _
                & " window.event.ctrlkey then" _
                & " window.event.keycode=0" _
                & ":window.event.cancelbubble=true" _
                & ":window.event.returnvalue=false'" _
                & " onkeypress='if window.event.keycode=13" _
                & " then bboxwait=false'><center>" _
                & "<div style='padding:10px;background-color:lightblue'>" _
                & "<b>&nbsp" & sPrompt & "<b>&nbsp</div><p>" _
                & "<table bgcolor=cornsilk cellspacing=10><tr><td>" _
                & " <b>User:</b></td><td>" _
                & "<input type=text size=10 id=user value='" _
                & sDefault & "'>" _
                & "</td><tr><td> <b>Password:</b></td><td>" _
                & "<input type=password size=12 id=pass>" _ 
                & "</td></tr></table><br>" _
                & "<button onclick='bboxwait=false;'>" _
                & "&nbsp;Okay&nbsp;" _
                & "</button> &nbsp; <button onclick=" _
                & "'document.all.user.value=""CANCELLED"";" _
                & "document.all.pass.value="""";" _
                & "bboxwait=false;'>Cancel" _
                & "</button></center></body></html>"
           .close
           Do Until .ReadyState = "complete" : WScript.Sleep 100 : Loop
           .all.user.focus
           .all.user.select ' Optional
           oIE.Visible = True
           CreateObject("Wscript.Shell")_
             .Appactivate "Password _"
           PasswordBox = Array("CANCELLED")
           On Error Resume Next
           Do While .parentWindow.bBoxWait
             if Err Then Exit Function
             WScript.Sleep 100
           Loop
           oIE.Visible = False
           PasswordBox = Array(.all.user.value, _
                               .all.pass.value)
         End With ' document
       End With   ' IE
     End Function
     

    dm_4ever

    My philosophy: K.I.S.S - Keep It Simple Stupid
    Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
    Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
    #2
      jeh332

      • Total Posts : 8
      • Scores: 0
      • Reward points : 0
      • Joined: 1/25/2008
      • Status: offline
      RE: IE form to VBScript Monday, January 28, 2008 4:38 AM (permalink)
      0
      I'm new to VBS so a bit more direction would help.  Where am I going wrong with my code?
      #3
        jeh332

        • Total Posts : 8
        • Scores: 0
        • Reward points : 0
        • Joined: 1/25/2008
        • Status: offline
        RE: IE form to VBScript Monday, January 28, 2008 5:57 AM (permalink)
        0
        Why doesn't it like this line of code in my do while loop:
         
        oIE.Document.script.CheckVal=false
        #4
          ebgreen

          • Total Posts : 8081
          • Scores: 94
          • Reward points : 0
          • Joined: 7/12/2005
          • Status: offline
          RE: IE form to VBScript Monday, January 28, 2008 6:17 AM (permalink)
          0
          The document object does not have a .Script property.
          "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
          Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
          http://www.visualbasicscript.com/m_47117/tm.htm
          #5
            jeh332

            • Total Posts : 8
            • Scores: 0
            • Reward points : 0
            • Joined: 1/25/2008
            • Status: offline
            RE: IE form to VBScript Monday, January 28, 2008 6:35 AM (permalink)
            0
            Any help for the proper syntax for doing this then?
             
            I need to check the value of the checkVal function and loop while it is still 0.
            #6
              ebgreen

              • Total Posts : 8081
              • Scores: 94
              • Reward points : 0
              • Joined: 7/12/2005
              • Status: offline
              RE: IE form to VBScript Monday, January 28, 2008 6:38 AM (permalink)
              0
              Instead of having the buttons change the value of a variable, have them change the value of a hidden text field. Then you can look for the value of that field.
              "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
              Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
              http://www.visualbasicscript.com/m_47117/tm.htm
              #7
                jeh332

                • Total Posts : 8
                • Scores: 0
                • Reward points : 0
                • Joined: 1/25/2008
                • Status: offline
                RE: IE form to VBScript Monday, January 28, 2008 7:30 AM (permalink)
                0
                <html>
                 <head>
                 </head>
                  
                 <script language="VBScript">
                  Sub updateStatus
                   formStatus.value = 1
                  End Sub
                 </script>
                 </head>
                 <body>
                 <form name="ValidForm">
                  <p>
                  <input type="hidden" name="formStatus" value = 0>
                  <input type="checkbox" name="serviceArea" value= 0 CHECKED>Service Area &nbsp;<br>
                  <input type="checkbox" name="actors" value="1" CHECKED>Actors &nbsp;<br>
                  <input type="checkbox" name="tools" value="1" CHECKED>Tools &nbsp;<br>
                  <input type="checkbox" name="preActivities" value="1" CHECKED>Pre-Activities &nbsp;<br>
                  <input type="checkbox" name="postActivities" value="1" CHECKED>Post-Activies &nbsp;<br>
                  <input type="checkbox" name="goal" value="1" CHECKED>Goal &nbsp;<br>
                  <input type="checkbox" name="description" value="1" CHECKED>Description &nbsp;<br>
                  <input type="button" name="button1" value="OK" onClick="updateStatus">
                  </p>
                 </form>
                 </body>
                 

                 
                 Option Explicit
                  Dim oIE
                  Dim checkServiceArea, checkActors, checkTools, checkGoal, checkDescription, checkPreActivities, checkPostActivities
                  
                  
                  'Launch Internet Explorer
                  Set oIE = CreateObject("InternetExplorer.Application")
                    oIE.left=50             ' window position
                    oIE.top = 100           ' and other properties
                    oIE.height = 400
                    oIE.width = 450
                    oIE.menubar = 0         ' no menu
                    oIE.toolbar = 0
                    oIE.statusbar = 0
                    oIE.navigate "C:\Program Files\Metis\Metis6.0\xml\http\xml.bah.com\xml\scripting\esartoword.htm"  ' Form
                    oIE.visible = 1
                  
                  ' Wait till MSIE is ready
                    Do While (oIE.Busy)      
                    Loop
                   
                   
                  ' Wait till the user clicks the OK button
                   On Error Resume Next  
                   Do  ' Wait till OK button is clicked
                   Loop While (oIE.Document.ValidForm.formStatus.Value = 0)
                   
                   
                  ' User has clicked the OK button, retrieve the values
                   checkServiceArea = oIE.Document.ValidForm.serviceArea.Value
                   checkActors = oIE.Document.ValidForm.actors.Value
                   checkTools = oIE.Document.ValidForm.tools.Value
                   checkGoal = oIE.Document.ValidForm.goal.Value
                   checkDescription = oIE.Document.ValidForm.description.Value
                   checkPreActivities = oIE.Document.ValidForm.preActivities.Value
                   checkPostActivities = oIE.Document.ValidForm.postActivities.Value
                   
                   oIE.Quit()             ' close Internet Explorer
                   Set oIE = Nothing      ' reset object variable 
                  'End
                 
                 

                 
                 
                Now it sits in loop, Button does nothing.  Only thing that I can think of is that my formStatus.value = 1
                sytax in my updateSatus function is wrong but I tried many variants.  (Script does pass loop when fromStatus is set to 1 on default)  So only thing that is hlding this up is that I cannot get formStatus to update to 1 on button click.
                #8
                  ebgreen

                  • Total Posts : 8081
                  • Scores: 94
                  • Reward points : 0
                  • Joined: 7/12/2005
                  • Status: offline
                  RE: IE form to VBScript Monday, January 28, 2008 7:32 AM (permalink)
                  0
                  Why do you have On Error Resume Next in there?
                  "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                  Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                  http://www.visualbasicscript.com/m_47117/tm.htm
                  #9
                    jeh332

                    • Total Posts : 8
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 1/25/2008
                    • Status: offline
                    RE: IE form to VBScript Monday, January 28, 2008 4:52 PM (permalink)
                    0
                    I actually I have that commented out in my code.  Came from the original code that I been taking from.  But with that commented out it does what I explained in my previous post. 
                    #10
                      ebgreen

                      • Total Posts : 8081
                      • Scores: 94
                      • Reward points : 0
                      • Joined: 7/12/2005
                      • Status: offline
                      RE: IE form to VBScript Tuesday, January 29, 2008 2:18 AM (permalink)
                      0
                      Please post the actual code that you are actually running so we can solve your actual problem.
                      "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                      Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                      http://www.visualbasicscript.com/m_47117/tm.htm
                      #11
                        ehvbs

                        • Total Posts : 3310
                        • Scores: 110
                        • Reward points : 0
                        • Joined: 6/22/2005
                        • Location: Germany
                        • Status: offline
                        RE: IE form to VBScript Tuesday, January 29, 2008 2:33 AM (permalink)
                        0
                        Hi jeh332,

                        did you consider using a .hta instead of the .html/.vbs combo?

                        Regards

                        ehvbs

                        #12
                          jeh332

                          • Total Posts : 8
                          • Scores: 0
                          • Reward points : 0
                          • Joined: 1/25/2008
                          • Status: offline
                          RE: IE form to VBScript Tuesday, January 29, 2008 3:43 AM (permalink)
                          0
                          VBS:
                           Option Explicit
                            Dim oIE
                            Dim checkServiceArea, checkActors, checkTools, checkGoal, checkDescription, checkPreActivities, checkPostActivities
                            
                            
                            'Launch Internet Explorer
                            Set oIE = CreateObject("InternetExplorer.Application")
                              oIE.left=50             ' window position
                              oIE.top = 100           ' and other properties
                              oIE.height = 400
                              oIE.width = 450
                              oIE.menubar = 0         ' no menu
                              oIE.toolbar = 0
                              oIE.statusbar = 0
                              oIE.navigate "C:\Program Files\Metis\Metis6.0\xml\http\xml.bah.com\xml\scripting\esartoword.htm"  ' Form
                              oIE.visible = True
                            
                            ' Wait till MSIE is ready
                              Do While (oIE.Busy)      
                              Loop
                             
                             
                            ' Wait till the user clicks the OK button
                             'On Error Resume Next  
                             Do  ' Wait till OK button is clicked
                             Loop While (oIE.Document.ValidForm.formStatus.Value = 0)
                             
                             
                             
                            ' User has clicked the OK button, retrieve the values
                             checkServiceArea = oIE.Document.ValidForm.serviceArea.Value
                             checkActors = oIE.Document.ValidForm.actors.Value
                             checkTools = oIE.Document.ValidForm.tools.Value
                             checkGoal = oIE.Document.ValidForm.goal.Value
                             checkDescription = oIE.Document.ValidForm.description.Value
                             checkPreActivities = oIE.Document.ValidForm.preActivities.Value
                             checkPostActivities = oIE.Document.ValidForm.postActivities.Value
                             
                             oIE.Quit()             ' close Internet Explorer
                             Set oIE = Nothing      ' reset object variable 
                            'End
                           

                           
                          HTML:
                            <html>
                           <head>
                            
                           <script language="VBScript">
                            Sub updateStatus
                             formStatus.value = 1
                            End Sub
                           </script>
                           
                           </head>
                            
                           <body>
                           <form name="ValidForm">
                            <p>
                            <input type="hidden" name="formStatus" value = 0>
                            <input type="checkbox" name="serviceArea" value= 0 CHECKED>Service Area &nbsp;<br>
                            <input type="checkbox" name="actors" value="1" CHECKED>Actors &nbsp;<br>
                            <input type="checkbox" name="tools" value="1" CHECKED>Tools &nbsp;<br>
                            <input type="checkbox" name="preActivities" value="1" CHECKED>Pre-Activities &nbsp;<br>
                            <input type="checkbox" name="postActivities" value="1" CHECKED>Post-Activies &nbsp;<br>
                            <input type="checkbox" name="goal" value="1" CHECKED>Goal &nbsp;<br>
                            <input type="checkbox" name="description" value="1" CHECKED>Description &nbsp;<br>
                            <input type="button" name="button1" value="OK" onClick="updateStatus">
                            </p>
                           </form>
                           </body>
                           </html>
                           

                          #13
                            ebgreen

                            • Total Posts : 8081
                            • Scores: 94
                            • Reward points : 0
                            • Joined: 7/12/2005
                            • Status: offline
                            RE: IE form to VBScript Tuesday, January 29, 2008 4:00 AM (permalink)
                            0
                            Try changing this:
                             
                             Do  ' Wait till OK button is clicked
                             Loop While (oIE.Document.ValidForm.formStatus.Value = 0)
                             
                            to this:
                             
                            While (oIE.Document.ValidForm.formStatus.Value = 0)
                                WScript.Sleep 1000
                            Wend
                            "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                            Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                            http://www.visualbasicscript.com/m_47117/tm.htm
                            #14
                              jeh332

                              • Total Posts : 8
                              • Scores: 0
                              • Reward points : 0
                              • Joined: 1/25/2008
                              • Status: offline
                              RE: IE form to VBScript Tuesday, January 29, 2008 5:01 AM (permalink)
                              0
                              Got it to work for the most part.  Just a couple more questions to finish this up.  What is the method to make the IE wondow load to the front?
                              and ehVBS,  I was looking into those HTA files and they seem like they could work better than using an IE app.  How do I call a .hta file from a VBS script?
                               
                               
                              Thanks everyone for their help so far.
                               
                              Here's my code:
                               
                               Option Explicit
                                Dim oIE
                                Dim checkServiceArea, checkActors, checkTools, checkGoal, checkDescription, checkPreActivities, checkPostActivities
                                
                                
                                'Launch Internet Explorer
                                Set oIE = CreateObject("InternetExplorer.Application")
                                  oIE.left=50             ' window position
                                  oIE.top = 100           ' and other properties
                                  oIE.height = 400
                                  oIE.width = 450
                                  oIE.menubar = 0         ' no menu
                                  oIE.toolbar = 0
                                  oIE.statusbar = 0
                                  oIE.navigate "C:\Program Files\Metis\Metis6.0\xml\http\xml.bah.com\xml\scripting\esartoword.htm"  ' Form
                                  oIE.visible = True
                                
                                ' Wait till MSIE is ready
                                  Do While (oIE.Busy)      
                                  Loop
                                 
                                 
                                ' Wait till the user clicks the OK button
                                 'On Error Resume Next  
                                 Do  ' Wait till OK button is clicked
                                 Loop While (oIE.Document.form1.formStatus.Value = 0)
                                 
                                 
                                 
                                ' User has clicked the OK button, retrieve the values
                                 checkServiceArea = oIE.Document.form1.serviceArea.checked
                                 checkActors = oIE.Document.form1.actors.checked
                                 checkTools = oIE.Document.form1.tools.checked
                                 checkGoal = oIE.Document.form1.goal.checked
                                 checkDescription = oIE.Document.form1.description.checked
                                 checkPreActivities = oIE.Document.form1.preActivities.checked
                                 checkPostActivities = oIE.Document.form1.postActivities.checked
                                 
                                 MsgBox "Actors: " & checkActors
                                 
                                 
                                 oIE.Quit()             ' close Internet Explorer
                                 Set oIE = Nothing      ' reset object variable 
                                'End
                               

                               
                               <html>
                               <head>
                               </head>
                               <script language="VBScript">
                                Sub updateStatus
                                 form1.formStatus.Value = 1
                                End Sub
                               </script>
                               <body>
                                <p>
                                <form name="form1">
                                <input type="hidden" name="formStatus" Value = 0>
                                <input type="checkbox" name="serviceArea" checked="yes" >Service Area &nbsp;<br>
                                <input type="checkbox" name="actors" checked="yes">Actors &nbsp;<br>
                                <input type="checkbox" name="tools" checked="yes">Tools &nbsp;<br>
                                <input type="checkbox" name="preActivities" checked="yes">Pre-Activities &nbsp;<br>
                                <input type="checkbox" name="postActivities" checked="yes">Post-Activies &nbsp;<br>
                                <input type="checkbox" name="goal" checked="yes">Goal &nbsp;<br>
                                <input type="checkbox" name="description" checked="yes">Description &nbsp;<br>
                                <input type="button" name="button1" value="OK" onClick="updateStatus">
                                </form>
                                </p>
                               </body>
                               </html>
                               

                               
                              Ehvbs,
                              #15

                                Online Bookmarks Sharing: Share/Bookmark

                                Jump to:

                                Current active users

                                There are 0 members and 1 guests.

                                Icon Legend and Permission

                                • New Messages
                                • No New Messages
                                • Hot Topic w/ New Messages
                                • Hot Topic w/o New Messages
                                • Locked w/ New Messages
                                • Locked w/o New Messages
                                • Read Message
                                • Post New Thread
                                • Reply to message
                                • Post New Poll
                                • Submit Vote
                                • Post reward post
                                • Delete my own posts
                                • Delete my own threads
                                • Rate post

                                2000-2012 ASPPlayground.NET Forum Version 3.8
                                mbt shoes www.wileywilson.com