Forum Discussion
ekiza23
11 years agoContributor
Have you tried the Timers object to create a timeout if there is no interaction on your user form?
http://support.smartbear.com/viewarticle/55006/
Here is some code I had on that. It creates a userform with after setting useDefaultValues = true
Then, all other interaction with the user form will set useDefaultValues = false.
The timeOutForUserInteraction Sub will check if useDefaultValues is still true, and if so, assume it is an unattended run, hide the form and continue with the default values.
http://support.smartbear.com/viewarticle/55006/
Here is some code I had on that. It creates a userform with after setting useDefaultValues = true
Then, all other interaction with the user form will set useDefaultValues = false.
The timeOutForUserInteraction Sub will check if useDefaultValues is still true, and if so, assume it is an unattended run, hide the form and continue with the default values.
Function Utils_BrowseFile_TimeoutForm(strDefaultFile, iTimeout)
useDefaultValues = true
pathFile = strDefaultFile
Set form = UserForms.Utils_BrowseFileForm
form.strFile.Text = pathFile
form.dlgBrowseFile.InitialDir = Project.Path + "Resources\"
form.dlgBrowseFile.FileName = ""
form.ModalResult = mrNone
isPathReady = false
' Adds a new object to the Timers collection
Set Timer1 = Utils.Timers.Add(iTimeout, "Utils_BrowseFile.timeOutForUserInteraction", false)
Timer1.Name = "BrowseFileTimer"
form.Show
Timer1.Enabled = true
While Not isPathReady
Sleep(1000)
Wend
Timer1.Enabled = false
Utils_BrowseFile_TimeoutForm = pathFile
End Function
Sub Utils_BrowseFileForm_strFile_OnButtonClick(Sender)
useDefaultValues = false
Set dialog = UserForms.Utils_BrowseFileForm.dlgBrowseFile
dialog.InitialDir = Project.Path + "Resources\"
dialog.FileName = ""
If dialog.Execute Then
Sender.Text = dialog.FileName
End If
End Sub
Sub Utils_BrowseFileForm_strFile_onUserInteraction(Sender)
useDefaultValues = false
End Sub
Sub timeOutForUserInteraction
Log.Message ("timeOutForUserInteraction: " & useDefaultValues)
Timer1.Enabled = false
If useDefaultValues = true Then
form.Hide
End If
End Sub
Function Utils_BrowseFileForm_OnHide(Sender)
If form.ModalResult = mrOk Then
pathFile = form.strFile.Text
End If
isPathReady = true
End Function
Sub Utils_BrowseFileForm_btnOK_OnClick(Sender)
useDefaultValues = false
form.ModalResult = mrOk
form.Hide
End Sub