Why isn't this App closing?
I need the VB app to shut itself down once IE launches and it isn't currently. Here is the code, probably simple I'm just missing it.
VB Code:
Private Sub Form_Load()
Dim objMSIE
Dim boolFileExists As Boolean
Dim strNotFound As String
Dim strStatus As String
Set objMSIE = CreateObject("InternetExplorer.Application")
If Err.Number = 0 Then 'No error
boolFileExists = True
outrc = 0
Else
boolFileExists = False
strNotFound = "I cannot find Internet Explorer." & vbCrLf & "Please download Internet Explorer from www.microsoft.com/windows/ie"
MsgBox strNotFound, vbCritical, "Application Error"
outrc = 1
Exit Sub
End If
objMSIE.Navigate ("To a website")
objMSIE.Visible = True
Set PublicObjectMSIE = objMSIE
strStatus = PublicObjectMSIE.StatusText
Select Case strStatus
Case "Done"
End
End Select
End Sub
Re: Why isn't this App closing?
Is the strStatus variable equal to "Done". Step through your code to check or add a Debug statement.
VB Code:
Debug.Print strStatus
Select Case strStatus
Case "Done"
End
End Select
Re: Why isn't this App closing?
Yeah strStatus returns done and it should step through the case statement but it's not.
Re: Why isn't this App closing?
Well, I guess until I can resolve this I'll remove the case statement and just end it.
Any guesses as to why that wouldn't work as long as strStatus comes back as "Done"?
Thanks
Re: Why isn't this App closing?
If the Case statement doesn't accept "Done" as returned by strStatus, check if the string doesn't contain other characters, such as Chr(0) or empty spaces (try Trim()). Also, when ending the program, don't use End if you're not calling it from within a module. And set the IE object to nothing before quitting. :)
VB Code:
Set ojbMSIE = Nothing 'Clean object
Unload Me 'No more End
Re: Why isn't this App closing?
Don't ever use End. The best way to end your program is to unload all your forms and set them to Nothing.
Re: Why isn't this App closing?
I actually had the forms unload and set the objects to nothing and it wasn't working, but I figured at the least the End command would shut it down no matter what.
The strStatus is getting passed as exactly "Done", so I'm not sure what is holding the form open.
Is it OK to unload all the forms set objects to nothing AND use the end command?
Re: Why isn't this App closing?
Quote:
Originally Posted by bat711
I actually had the forms unload and set the objects to nothing and it wasn't working, but I figured at the least the End command would shut it down no matter what.
The strStatus is getting passed as exactly "Done", so I'm not sure what is holding the form open.
Is it OK to unload all the forms set objects to nothing AND use the end command?
Sure, if you unload and set to Nothing first. You should also set any created objects like objMSIE to Nothing before you unload your forms.
Re: Why isn't this App closing?
Like this?
VB Code:
Select Case strStatus
Case "Done"
Set PublicObjectMSIE = Nothing
Set objMSIE = Nothing
Unload frmIELaunch
End Select
End
Re: Why isn't this App closing?
That should work but I think you should change your Select to
VB Code:
Select Case True
Case InStr(1, strStatus, "Done") > 0
Set PublicObjectMSIE = Nothing
Set objMSIE = Nothing
Unload frmIELaunch
End Select
I've never done what you are trying to do but when I look at waht is returned in StatusText in contains some unprintable characters after "Done".
Re: Why isn't this App closing?
Quote:
Originally Posted by MartinLiss
That should work but I think you should change your Select to
VB Code:
Select Case True
Case InStr(1, strStatus, "Done") > 0
.
Nice way to write a select case like that. :) A little time ago I had to use InStr and I ended up using multiple If statements, because I didn't realize it could be done through Select Case.