Results 1 to 11 of 11

Thread: Why isn't this App closing?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Question 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:
    1. Private Sub Form_Load()
    2.  
    3. Dim objMSIE
    4. Dim boolFileExists As Boolean
    5. Dim strNotFound As String
    6. Dim strStatus As String
    7.  
    8. Set objMSIE = CreateObject("InternetExplorer.Application")
    9. If Err.Number = 0 Then 'No error
    10.             boolFileExists = True
    11.             outrc = 0
    12.         Else
    13.             boolFileExists = False
    14.             strNotFound = "I cannot find Internet Explorer." & vbCrLf & "Please download Internet Explorer from www.microsoft.com/windows/ie"
    15.             MsgBox strNotFound, vbCritical, "Application Error"
    16.             outrc = 1
    17.             Exit Sub
    18.         End If
    19.  
    20. objMSIE.Navigate ("To a website")
    21. objMSIE.Visible = True
    22.  
    23. Set PublicObjectMSIE = objMSIE
    24. strStatus = PublicObjectMSIE.StatusText
    25.    
    26.     Select Case strStatus
    27.         Case "Done"
    28.             End
    29.     End Select
    30.  
    31. End Sub

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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:
    1. Debug.Print strStatus
    2.  
    3. Select Case strStatus
    4.     Case "Done"
    5.          End
    6. End Select

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Re: Why isn't this App closing?

    Yeah strStatus returns done and it should step through the case statement but it's not.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    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

  5. #5
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    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:
    1. Set ojbMSIE = Nothing 'Clean object
    2. Unload Me 'No more End
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  6. #6

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    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?

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Re: Why isn't this App closing?

    Like this?

    VB Code:
    1. Select Case strStatus
    2.         Case "Done"
    3.             Set PublicObjectMSIE = Nothing
    4.             Set objMSIE = Nothing
    5.             Unload frmIELaunch
    6.            
    7.     End Select
    8.  
    9. End

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Why isn't this App closing?

    That should work but I think you should change your Select to

    VB Code:
    1. Select Case True
    2.         Case InStr(1, strStatus, "Done") > 0
    3.            Set PublicObjectMSIE = Nothing
    4.             Set objMSIE = Nothing
    5.             Unload frmIELaunch
    6.     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".

  11. #11
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    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:
    1. Select Case True
    2.         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.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width