mardi 24 mars 2015

Communicating between forms in VB.net

I have a main form listening for communication on a COM port and another form with a button. The button opens a save file dialog box which, on successful return of the ShowDialog() method, sets a public string "FilePath" to the .FileName property and then writes a command to the serial port. The hardware listening on the other end sees this command and begins sending data. My main form sees this data and branches to a sub to collect it and save it. In this sub I try to access the "FilePath" public string from the other form to use as the save path for the data coming in but it is always "Nothing". The form has not closed yet, and I KNOW that that variable has been assigned in the button click handler...


What is going on?



Public Class frmDebug

Public FilePath As String

Private Sub Button_DumpDataflash_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_DumpDataflash.Click

SaveFileDialog1.Filter = "Binary File|*.bin"
SaveFileDialog1.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

If Not SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Exit Sub
End If

FilePath = SaveFileDialog1.FileName

frmMain.SerialPort1.Write(New Byte() {60}, 0, 1)

End Sub

End Class

Aucun commentaire:

Enregistrer un commentaire