CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Textbox

  1. #1
    Join Date
    Apr 2001
    Location
    Andhra Pradesh,INDIA
    Posts
    11

    Textbox

    suppose i have three textboxes in a form and when i write this code and leave two textboxes empty it is displaying the message twice i.e. if in the form five textboxes r left empty then the message("fields should not be left empty") is displayed five times.please help me out

    Public Sub CheckEmpty(frm As Form, ctl As Control)
    For Each ctl In frm
    If TypeOf ctl Is TextBox Then
    If ctl.Text = "" Then
    MsgBox " Feilds should not be empty "
    ctl.SetFocus
    End If
    End If
    Next ctl
    End Sub

    [email protected]


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Textbox

    You can jump out of any loop using the exit whatever statement.

    public Sub CheckEmpty(frm as Form, ctl as Control)
    ' start looping
    for Each ctl In frm
    If TypeOf ctl is TextBox then
    ' check if textbox is filled in
    If ctl.Text = "" then
    ' it isn't, display message
    MsgBox " Fields should not be empty "
    ' give the control the focus
    ctl.SetFocus
    ' stop checking for more
    ' Exit for is used, because we are in a for loop
    Exit for
    End If
    End If
    next ctl
    End Sub





    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured