I'm working with code developed by another unknown person that gathers data with an HTML form embedded within a VBScript, validates the data, then closes the form once all data is valid. Here's the form part of the HTML code:
[pre] ' Create IE object and set its appearance
Set objIESignon = CreateObject( "InternetExplorer.Application" )
objIESignon.Navigate "about:blank"
Wait_SURF_Window
objIESignon.Document.Title = "SURF Data"
objIESignon.ToolBar = False
objIESignon.Resizable = False
objIESignon.StatusBar = False
objIESignon.Left = 100
objIESignon.Top = 100
objIESignon.Width = 500
objIESignon.Height = 325
' Insert the HTML code to prompt for the dialog
objIESignon.Document.Body.InnerHTML = "<DIV align='center'>" & _
"<TABLE width='100%' id='table1' border=1 style='background-color: rgb(155, 205, 155)'>" & _
"<TR>" & _
"<TD colspan=2>Number of Updates:<br>" & _
"<INPUT name='txtNoU' title='Numeric 1 or 2 digits only' TYPE='text' SIZE= '15' ID='txtNoU'></TD>" & _
"</TR>" & _
"<TR>" & _
"<TD colspan=2>" & _
"Work Reassigned:</span><br>" & _
"<select name='ddlReassign' ID='ddlReassign'>" & _
"<option selected='selected' value=''>Select One</option>" & _
"<option value='Yes'>Yes</option>" & _
"<option value='No'>No</option>" & _
"</select></TD>" & _
"</TR>" & _
"<TR>" & _
"<TD colspan=2>Consulting SME Utilized:<br>" & _
"<select name='ddlSME' ID='ddlSME'>" & _
"<option selected='selected' value=''>Select One</option>" & _
"<option value='No'>No</option>" & _
"<option value='Yes1'>Yes-Resolution found documented in SOP</option>" & _
"<option value='Yes2'>Yes-Resolution needs to be documented in SOP</option>" & _
"</select></TD>" & _
"</TR>" & _
"<TR>" & _
"<TD colspan=2>Comments:<br>" & _
"<textarea maxlength=255 rows=2 cols=20 name ='txtComments' ID='txtComments' Title='Free flowing 255 characters'></textarea></TD>" & _
"</TR>" & _
"<TR>" & _
"<TD colspan=2><br>" & _
"<INPUT TYPE='submit' VALUE='Submit' OnClick='VBScript:Submit.Value=1'> " & _
"<INPUT TYPE='button' VALUE='Reset' OnClick='VBScript:Reset.Value=1'> " & _
"<INPUT TYPE='hidden' ID='Submit' NAME='Submit' VALUE='0'>" & _
"<INPUT TYPE='hidden' ID='Reset' NAME='Reset' VALUE='0'><br><br>" & _
"</TD>" & _
"</TR>" & _
"</TABLE>" & _
"</DIV>"
' Make the window visible
objIESignon.Visible = True
' Bring dialog window to top of window z order (in case it is under another window)
WShell.AppActivate "SURF Data"[/pre]
The form stays alive due to a Do While...Loop that terminates when the hidden Reset value becomes 1...meaning the reset button has been pressed, otherwise, the form waits until the user has submitted the required data by pressing the Submit button.
My issue is in the validation. I have this to decide whether or not all data is valid:
[pre] ' Validate entries before dialog can be dismissed
if NumIsValid(objIESignon.Document.GetElementById("txtNoU").Value) Then
if ReassignValid(objIESignon.Document.GetElementById("ddlReassign").Value) Then
if ConsultSMEValid(objIESignon.Document.GetElementById("ddlSME").Value) Then
exit do
end if
end if
end if[/pre]
Obviously, each if references a function that checks to see if the data is valid. If all three check out, we exit the Do Loop and the form should go away. That does work. What doesn't is if I test either of the three, the respective function tells them they need to enter a valid response, then waits for them to do so. Let's say I leave the number of updates blank. Here's the function that does the validation:
[pre]Function NumIsValid(NumOfUpdates)
Dim Updates
' So that we can modify it without modifying the incoming parameter
Updates = NumOfUpdates
if Len(Updates) > 2 Or Len(Updates) < 1 then
Msgbox "You must enter a number that is 1 or 2 digits long." & chr(13) & chr(13) & "For example: 1 or 34" & chr(13) & chr(13) + "Please enter a valid number of updates.",,"Invalid Number of Updates"
NumIsValid = False
Exit Function
end if
NumIsValid = True
End Function[/pre]
If "NumIsValid" is False, this next line should set the Submit button hidden element back to 0. All it does is stop the script. Any consecutive lines never get processed.
[pre]objIESignon.Document.GetElementById("Submit").Value = 0 ' reset back to not clicked[/pre]
Any idea on why it's not working? Or can you guide me to a better solution that will actually work?
[pre] ' Create IE object and set its appearance
Set objIESignon = CreateObject( "InternetExplorer.Application" )
objIESignon.Navigate "about:blank"
Wait_SURF_Window
objIESignon.Document.Title = "SURF Data"
objIESignon.ToolBar = False
objIESignon.Resizable = False
objIESignon.StatusBar = False
objIESignon.Left = 100
objIESignon.Top = 100
objIESignon.Width = 500
objIESignon.Height = 325
' Insert the HTML code to prompt for the dialog
objIESignon.Document.Body.InnerHTML = "<DIV align='center'>" & _
"<TABLE width='100%' id='table1' border=1 style='background-color: rgb(155, 205, 155)'>" & _
"<TR>" & _
"<TD colspan=2>Number of Updates:<br>" & _
"<INPUT name='txtNoU' title='Numeric 1 or 2 digits only' TYPE='text' SIZE= '15' ID='txtNoU'></TD>" & _
"</TR>" & _
"<TR>" & _
"<TD colspan=2>" & _
"Work Reassigned:</span><br>" & _
"<select name='ddlReassign' ID='ddlReassign'>" & _
"<option selected='selected' value=''>Select One</option>" & _
"<option value='Yes'>Yes</option>" & _
"<option value='No'>No</option>" & _
"</select></TD>" & _
"</TR>" & _
"<TR>" & _
"<TD colspan=2>Consulting SME Utilized:<br>" & _
"<select name='ddlSME' ID='ddlSME'>" & _
"<option selected='selected' value=''>Select One</option>" & _
"<option value='No'>No</option>" & _
"<option value='Yes1'>Yes-Resolution found documented in SOP</option>" & _
"<option value='Yes2'>Yes-Resolution needs to be documented in SOP</option>" & _
"</select></TD>" & _
"</TR>" & _
"<TR>" & _
"<TD colspan=2>Comments:<br>" & _
"<textarea maxlength=255 rows=2 cols=20 name ='txtComments' ID='txtComments' Title='Free flowing 255 characters'></textarea></TD>" & _
"</TR>" & _
"<TR>" & _
"<TD colspan=2><br>" & _
"<INPUT TYPE='submit' VALUE='Submit' OnClick='VBScript:Submit.Value=1'> " & _
"<INPUT TYPE='button' VALUE='Reset' OnClick='VBScript:Reset.Value=1'> " & _
"<INPUT TYPE='hidden' ID='Submit' NAME='Submit' VALUE='0'>" & _
"<INPUT TYPE='hidden' ID='Reset' NAME='Reset' VALUE='0'><br><br>" & _
"</TD>" & _
"</TR>" & _
"</TABLE>" & _
"</DIV>"
' Make the window visible
objIESignon.Visible = True
' Bring dialog window to top of window z order (in case it is under another window)
WShell.AppActivate "SURF Data"[/pre]
The form stays alive due to a Do While...Loop that terminates when the hidden Reset value becomes 1...meaning the reset button has been pressed, otherwise, the form waits until the user has submitted the required data by pressing the Submit button.
My issue is in the validation. I have this to decide whether or not all data is valid:
[pre] ' Validate entries before dialog can be dismissed
if NumIsValid(objIESignon.Document.GetElementById("txtNoU").Value) Then
if ReassignValid(objIESignon.Document.GetElementById("ddlReassign").Value) Then
if ConsultSMEValid(objIESignon.Document.GetElementById("ddlSME").Value) Then
exit do
end if
end if
end if[/pre]
Obviously, each if references a function that checks to see if the data is valid. If all three check out, we exit the Do Loop and the form should go away. That does work. What doesn't is if I test either of the three, the respective function tells them they need to enter a valid response, then waits for them to do so. Let's say I leave the number of updates blank. Here's the function that does the validation:
[pre]Function NumIsValid(NumOfUpdates)
Dim Updates
' So that we can modify it without modifying the incoming parameter
Updates = NumOfUpdates
if Len(Updates) > 2 Or Len(Updates) < 1 then
Msgbox "You must enter a number that is 1 or 2 digits long." & chr(13) & chr(13) & "For example: 1 or 34" & chr(13) & chr(13) + "Please enter a valid number of updates.",,"Invalid Number of Updates"
NumIsValid = False
Exit Function
end if
NumIsValid = True
End Function[/pre]
If "NumIsValid" is False, this next line should set the Submit button hidden element back to 0. All it does is stop the script. Any consecutive lines never get processed.
[pre]objIESignon.Document.GetElementById("Submit").Value = 0 ' reset back to not clicked[/pre]
Any idea on why it's not working? Or can you guide me to a better solution that will actually work?