[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

empty fields

Posted on 2006-05-01
1
Medium Priority
?
324 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:aplelois
1 Comment
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 2000 total points
ID: 16581854
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question