Can anyone tell me why this is not working
I'm creating a console application that performs a few system tasks. One of the things it does is check the registry for a certain key. If the key is not found then it displays a windows form that allows the user to input a value that will be inserted into the registry.
I want the console application to look for the closing of the form and then move on. My form displays ok, and even writes the key to the registry, but when I close the form the console never performs the action below.
This is what I have.
<hr>
'Console
<color="blue">
Try
prm = key.GetValue("parameters")
Catch ex As Exception
End Try
If (prm Is Nothing Or prm.Equals("")) Then
Dim sForm As New pForm
If (sForm.ShowDialog() = Windows.Forms.DialogResult.OK) Then
Console.WriteLine("Parameters saved!")
End If
Else
Console.WriteLine("All files found!")
End If
</color>
<hr>
'Form
<color="blue">
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
Dim key As RegistryKey
Try
key = Registry.CurrentUser.CreateSubKey("SOFTWARE\POSExport\Settings")
key.SetValue("parameters", Me.TxtLoc.Text)
Catch ex As Exception
Dim sw As New StreamWriter("Errors.txt")
sw.Write(ex.ToString)
sw.Close()
End Try
End Sub
Private Sub BtnCLose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCLose.Click
Me.Close()
End Sub
</color>

Mixed application console/windows.forms??
zydjohn
whodat
Also, if the form's only purpose is to specify the registry value, I would close the form in BtnSave_Click. Otherwise, you would need to check a flag of some sort or look for the registry value in BtnClose_Click to make sure the information was actually saved.
Other than that, I don't see any problems that would keep the code from continuing to run.