empty fields

hello,
I have 3 textbox in the save.vb and a button called save
I want to make sure the ppl dont leave empty fields
meaning if they only put name and last name but not
phone a windows will come and say you need to put
your phone number. how would I do that?

Public Class frmAdd
    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        Dim FileNo As Short
        On Error Resume Next

        FileNo = FreeFile()
        FileOpen(FileNo, "C:\Accounts.ini", OpenMode.Append, , OpenShare.Shared)
        PrintLine(FileNo, txtFirst.Text & ";" & txtLast.Text & ";" & txtPhone.Text)
        FileClose(FileNo)

        frmMain.Enabled = True
        frmMain.Activate()
        Me.Close()
    End Sub
End Class
apleloisAsked:
Who is Participating?
 
Brian CroweConnect With a Mentor Database AdministratorCommented:
simple solution below...

Public Class frmAdd
    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        Dim FileNo As Short
        On Error Resume Next

        if txtfirstname.text.trim.length = 0 then
            messagebox.show("No first bname provided")
            exit sub
        end if

        if txtlastname.text.trim.length = 0 then
            messagebox.show("No last name provided")
            exit sub
        end if

        if txtphone.text.trim.length = 0 then
            messagebox.show("No phone provided")
            exit sub
        end if

        FileNo = FreeFile()
        FileOpen(FileNo, "C:\Accounts.ini", OpenMode.Append, , OpenShare.Shared)
        PrintLine(FileNo, txtFirst.Text & ";" & txtLast.Text & ";" & txtPhone.Text)
        FileClose(FileNo)

        frmMain.Enabled = True
        frmMain.Activate()
        Me.Close()
    End Sub
End Class

A better solution might be to create a separate function to check for valid entries and return a true/false value to indicate success/failure before writing the data to the file.  You might want to look at performing some additional validation on the phone number as well.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.