Results 1 to 5 of 5

Thread: Can't Show Non-Modal Form...........!

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Question Can't Show Non-Modal Form...........!

    In a WebBrowser project, I have given users the option to set their default browser to my browser i.e. whenever any HTML file is opened in Windows Explorer, the HTML file should open with my browser. The project also houses a CheckBox for the browser to check whether it is the default browser or not. If not, then when the browser is run on the first time, a MsgBox should come up asking the user if he would like to set my browser as the default browser in his machine. If Yes, then my browser will be set as the default browser in that machine else the existing default browser will remain the default browser. This is how I am checking whether my browser is the default browser or not (NOTE: This is not my code):
    VB Code:
    1. Private Sub Form_Load()
    2.     If (frmBrowserOptions.chkDefault.Value = vbChecked) Then
    3.         Call CheckDefault
    4.     End If
    5. End Sub
    6.  
    7. Private Sub CheckDefault()
    8.     Dim success As Long
    9.     Dim sBrowser As String
    10.    
    11.     'success is passed and filled in the routine
    12.     sBrowser = GetBrowserName(success)
    13.    
    14.     'possible return values from the call returned in success
    15.     Select Case success
    16.     'the call succeeded
    17.         Case Is >= ERROR_FILE_SUCCESS
    18.             If (InStr(sBrowser, "MyBrowser.exe") = 0) Then
    19.                 If (vbYes = MsgBox("MyBrowser not default browser! Set it as default?", vbYesNo + vbQuestion)) Then
    20.                     Call frmBrowserOptions.cmdDefault_Click
    21.                 End If
    22.             End If
    23.             Exit Sub
    24.         'other possible return values
    25.         Case ERROR_FILE_NO_ASSOCIATION
    26.         Case ERROR_FILE_NOT_FOUND
    27.         Case ERROR_PATH_NOT_FOUND
    28.         Case ERROR_BAD_FORMAT
    29.         Case Else
    30.     End Select
    31. End Sub
    32.  
    33. Private Function GetBrowserName(dwFlagReturned As Long) As String
    34.     Dim hFile As Long
    35.     Dim sResult As String
    36.     Dim sTempFolder As String
    37.        
    38.     'get the user's temp folder
    39.     sTempFolder = GetTempDir()
    40.    
    41.     'create a dummy html file in the temp dir
    42.     hFile = FreeFile
    43.     Open sTempFolder & "dummy.html" For Output As #hFile
    44.     Close #hFile
    45.  
    46.     'get the file path & name associated with the file
    47.     sResult = Space$(MAX_PATH)
    48.     dwFlagReturned = FindExecutable("dummy.html", sTempFolder, sResult)
    49.  
    50.     'clean up
    51.     Kill sTempFolder & "dummy.html"
    52.    
    53.     'return result
    54.     GetBrowserName = TrimNull(sResult)
    55. End Function
    56.  
    57. Private Function TrimNull(Item As String)
    58.     Dim pos As Integer
    59.     pos = InStr(Item, Chr$(0))
    60.     If pos Then
    61.         TrimNull = Left$(Item, pos - 1)
    62.     Else
    63.         TrimNull = Item
    64.     End If
    65. End Function
    66.  
    67. Public Function GetTempDir() As String
    68.     Dim nSize As Long
    69.     Dim tmp As String
    70.     tmp = Space$(MAX_PATH)
    71.     nSize = Len(tmp)
    72.     Call GetTempPath(nSize, tmp)
    73.     GetTempDir = TrimNull(tmp)
    74. End Function
    75.  
    76. 'this is the [i]cmdDefault_Click[/i] event function in another Form named [i]frmBrowserOptions[/i]
    77. Sub cmdDefault_Click()
    78.     ......................
    79.     ......................
    80.     ......................
    81. End Sub
    Assume that my browser is not the default browser. Now when I run the browser from the IDE, the MsgBox asking the user whether he would like to set my browser as the default browser or not comes up as expected but when I compile the project into an EXE & then open my browser (again assuming that my browser isn't the default browser), though the MsgBox comes up but immediately after that, VB generates the Can't show non-modal form when modal form is displayed.

    Next irrespective of whether I click Yes or No in the MsgBox, the following error gets generated:

    An exception 'Unhandled Win32 Exception' has occured in MyBrowser.exe.

    However, no debuggers are registered that can debug this exception. Unable to JIT debug.


    After this, the browser closes. Now how do I avoid these 2 errors when I run the EXE? Please note that these 2 errors don't get generated when I run the project from the VB IDE.
    Last edited by arpan_de; Jan 8th, 2006 at 12:56 PM.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Can't Show Non-Modal Form...........!

    I can't duplicate the problem. Try adding line numbers and add errorhandlers. In error handlrs display the eror line. Like,
    VB Code:
    1. Form_Load_Err:
    2.         MsgBox Err.Description & vbCrLf & _
    3.                "in Project1.Form1.Form_Load " & _
    4.                "at line " & Erl, vbCritical Or vbOKOnly, "ERROR !"

    My suspicion is,
    In the If (frmBrowserOptions.chkDefault.Value = vbChecked) Then line, VB autometically loads the frmBrowserOptions. This may be causing the problem.
    Try unloading the frmBrowserOptions before and/or after the Call CheckDefault line.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Can't Show Non-Modal Form...........!

    Try adding line numbers and add errorhandlers. In error handlrs display the eror line. Like
    The MsgBox in the ErrorrHandler doesn't get executed at all.
    In the If (frmBrowserOptions.chkDefault.Value = vbChecked) Then line, VB autometically loads the frmBrowserOptions. This may be causing the problem.
    Try unloading the frmBrowserOptions before and/or after the Call CheckDefault line.
    I tried that but it doesn't make any difference; the 2 errors are still thrown.

    What next?

    iPrank, please do something about my other post.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  4. #4

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Can't Show Non-Modal Form...........!

    Forgot to mention.................
    VB autometically loads the frmBrowserOptions.
    Yeah you are absolutely correct. I added a MsgBox 1 in the frmBrowserOptions Form_Load event function; so the MsgBox gets executed twice but if I comment the If (frmBrowserOptions.chkDefault.Value = vbChecked) condition, then the MsgBox comes up only once.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  5. #5

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Can't Show Non-Modal Form...........!

    Tring.....tring......anyone out there willing to lend a helping hand to me?


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

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