Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27226

VS 2010 Enabling a button when fields are filled, write to file

$
0
0
I would like to enable a button after all of the necessary data is entered. After all of the data is entered, it needs to write to file. I have this code:

Code:

Private Sub btnAccept_Handles(sender As System.Object, e As System.EventArgs) Handles btnAccept.HandleCreated
        If (txtCustName.Text <> "") And (txtCustStAdd.Text <> "") And (txtCustAddCity.Text <> "") And (cboState.SelectedItem <> "") And (mtbZip.Text <> "") And (mtbCustPh.Text <> "") Then
            btnAccept.Enabled = True
        Else
            btnAccept.Enabled = False
        End If
        Dim SaveFile As New SaveFileDialog
        SaveFile.FileName = "Customer Log File"
        SaveFile.Filter = "Transactional Log File (*.txt)|*.txt"
        SaveFile.Title = "Save File"
        SaveFile.ShowDialog()
        Try
            Dim Write As New System.IO.StreamWriter(SaveFile.FileName)
            Write.Write(txtCustName.Text)
            Write.Close()
        Catch ex As Exception
        End Try
    End Sub

However, the button isn't enabling after all of the fields have data entered and the text file is saving before the data gets entered. Is there a better way to write this code?

Viewing all articles
Browse latest Browse all 27226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>