mark
mark

Reputation: 3

How to continue after using a form?

Firstly, I have no real understanding of VB.net but have done some VBA programming for the CAD software MicroStation. I have inherited another programmers VB code and with a lot of help made some changes but have a current problem...

I have added a form to prompt the user to either click a button to run the programme again, close it completely, or close it and open the file it created. The first two options I have working but the last requires the programme to continue on from after I invoked the form as the command will only work from within this particular Sub. In VBA I simply define an If statement to check whether the 'OpenFile' button has been clicked if yes continue if not skip, etc but I can't figure it out for the VB. In desperation I tried o define a GOTO in the form button but I don't know how to relate it back to the particular sub ie GOTO MakeFile(OpenFileHere) where MakeFile is the sub and 'OpenFileHere' is the line marker. Can anyone suggest what I should do or point me to an example to follow the processes? Below is the section I am trying to work with 'MakeAnother' is my form and 'MakeFile' is the sub below:

 Dim strFullName As String
    If Right(Trim(strPath), 1) <> "\" Then
        strPath = strPath & "\"
    End If
    strFullName = strPath + strName
    If UCase(strFullName) = UCase(MSApp.ActiveWorkspace.ConfigurationVariableValue("_DGNFILE", True)) Then
        MsgBox("Cannot Create file as this is the currently open file!", vbOKOnly, "File Create")
        Exit Sub
    End If
    If MakeFolderPath(strPath) = True Then

        If System.IO.File.Exists(strFullName) Then
            If MsgBox("File Exists - Overwrite?", vbOKCancel, "File Create") = vbCancel Then
                Exit Sub
            End If
        End If

        System.IO.File.Copy(seed, strFullName, True)

        '#############################################################
        '### following line is used to open the newly created file ###
        ' MSApp.CadInputQueue.SendCommand("newfile " + strFullName)
        MakeAnother.Modal.Equals(True)
        MakeAnother.Show()

    End If
OpenFileHere:
    If MakeFile.OpenThisFile = "defined" Then
        MsgBox("made it through")
        MSApp.CadInputQueue.SendCommand("newfile " + strFullName)
    End If

Upvotes: 0

Views: 186

Answers (1)

ADP_X
ADP_X

Reputation: 333

I would use in the Prompt form, something like this:

Public Class FPrompt

Public Enum ExitState
    Close
    ContinueExec
    OpenFile
End Enum

Private StateVariable As ExitState



Public ReadOnly Property Response()
    Get
        Return StateVariable
    End Get

End Property

Private Sub btnContinue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnContinue.Click
    Me.StateVariable = ExitState.ContinueExec
    Me.Close()
End Sub


Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.StateVariable = ExitState.Close
    Me.Close()
End Sub

Private Sub btnOpenfile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOpenfile.Click
    Me.StateVariable = ExitState.OpenFile
    Me.Close()
End Sub

End Class

And in its formclosing event retrieve (From the main sub function) the response property and do what desired.

[UPDATE]

Friend WithEvents objX As FPrompt

Sub Main()

    objX = New FPrompt
    objX.ShowDialog()
    If objX.Response = FPrompt.ExitState.Close Then
    ElseIf objX.Response = FPrompt.ExitState.ContinueExec Then
    ElseIf objX.Response = FPrompt.ExitState.OpenFile Then
    End If

End Sub

Hope it helps.

Upvotes: 1

Related Questions