none
Me.Close() problems RRS feed

  • Question

  • Hi,

    I'm trying to close my application after displaying a message.  I have tried Application.Exit(), Me.Close(), but neither seem to work.  This code is a custom Sub.  Any suggestions on how to get out of it? 

    Basically, I'm reading some JSON and if there are 0 records, or more than one records, I need to exit.

    The last line of code ends up giving an error to the user, and then it exits.

                If (jObject("records").ToString() = "0") Then
                    MsgBox("Please add a record for " & txtCard.Text & " to the Contract Database before linking to this As-Built point.", MsgBoxStyle.Exclamation, "Missing Drawing Entry")
                    Me.Close()
                End If
    
                If (jObject("records").ToString() <> "1") Then
                    MsgBox("Multiple records for this Card Number exist in the DrawingData table.", MsgBoxStyle.Exclamation, "Error")
                    Me.Close()
                End If
    
    
                Dim drawingUID As String = jObject("results")(0)("id").ToString()


    Brian

    Thursday, March 28, 2019 1:46 PM

Answers

  • In VB.NET End does not seem to be an option.

    I resolved this by adding an Exit Sub and using a boolean.  Once the form is activated, I check the valueof the boolean, and if False, then I do a Me.Close()

                Dim numRecords As Integer = jObject("records")
    
                If (numRecords = 0) Then
                    MsgBox("Please add a record for " & txtCard.Text & " to the Contract Database before linking to this As-Built point.", MsgBoxStyle.Exclamation, "Missing Drawing Entry")
                    drawingsFound = False
                    Exit Sub
                End If
    
                If (numRecords > 1) Then
                    MsgBox("Multiple records for this Card Number exist in the DrawingData table.", MsgBoxStyle.Exclamation, "Error")
                    drawingsFound = False
                    Exit Sub
                End If
    
                Dim drawingUID As String = jObject("results")(0)("id").ToString()

    and in my Form.Activated event:

        Private Sub frmAsBuilts_Activated(sender As Object, e As EventArgs) Handles MyBase.Activated
            If drawingsFound = False Then
                Me.Close()
            End If
    
        End Sub


    Brian

    • Marked as answer by Khabibulla Thursday, March 28, 2019 3:40 PM
    Thursday, March 28, 2019 3:39 PM

All replies

  • After the close you should not execute code, except in the closing event.

    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein

    Thursday, March 28, 2019 2:15 PM
  • Hello,

    Please post all relevant code using the code button and provide the error message, if we don't know the full context of the code flow and don't know the error all we can do is ask you as I'm now for more details.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, March 28, 2019 2:27 PM
    Moderator
  • Hi

    Have you tried

    End
    which should just abort everything and end the application.


    Regards Les, Livingston, Scotland

    Thursday, March 28, 2019 2:34 PM
  • In VB.NET End does not seem to be an option.

    I resolved this by adding an Exit Sub and using a boolean.  Once the form is activated, I check the valueof the boolean, and if False, then I do a Me.Close()

                Dim numRecords As Integer = jObject("records")
    
                If (numRecords = 0) Then
                    MsgBox("Please add a record for " & txtCard.Text & " to the Contract Database before linking to this As-Built point.", MsgBoxStyle.Exclamation, "Missing Drawing Entry")
                    drawingsFound = False
                    Exit Sub
                End If
    
                If (numRecords > 1) Then
                    MsgBox("Multiple records for this Card Number exist in the DrawingData table.", MsgBoxStyle.Exclamation, "Error")
                    drawingsFound = False
                    Exit Sub
                End If
    
                Dim drawingUID As String = jObject("results")(0)("id").ToString()

    and in my Form.Activated event:

        Private Sub frmAsBuilts_Activated(sender As Object, e As EventArgs) Handles MyBase.Activated
            If drawingsFound = False Then
                Me.Close()
            End If
    
        End Sub


    Brian

    • Marked as answer by Khabibulla Thursday, March 28, 2019 3:40 PM
    Thursday, March 28, 2019 3:39 PM
  • In VB.NET End does not seem to be an option.


    Brian

    Hi

    Well, tell Microsoft as they dont seem to know - End Statement


    Regards Les, Livingston, Scotland



    • Edited by leshay Thursday, March 28, 2019 3:50 PM
    Thursday, March 28, 2019 3:49 PM
  • Maybe it's just my version of .NET.  


    Brian

    Thursday, March 28, 2019 5:10 PM