Results 1 to 7 of 7

Thread: Check TextBox Value

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108

    Check TextBox Value

    i have about 21 textbox in my form

    example i got 1 client name textbox and 1 current age textbox and one is profit textbox

    how can i check all the textbox in my form ???

    the client name text box is string
    the current aga textbox is number
    the profit textbox is double

    how to use the for loop to check all the textbox ??

    can someone please help me ???

    and i have the coding below

    Dim Ctr As Control

    For Each Ctr In Me.Controls

    If TypeOf Ctr Is TextBox Then

    If Ctr.Text = "" Then

    CheckTextBoxIsEmpty += 1
    Else
    CheckTextBoxIsEmpty = 0

    End If

    End If
    Next

    this check is emty or not

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Just a couple of changes, assuming that you want the variable CheckTextBoxIsEmpty to hold the number of empty textboxes.

    VB Code:
    1. Dim Ctr As Control
    2. Dim CheckTextBoxIsEmpty AS Integer =0
    3.  
    4. For Each Ctr In Me.Controls
    5.  
    6. If TypeOf Ctr Is TextBox Then
    7.  
    8. If Ctr.Text = "" Then
    9.  
    10. CheckTextBoxIsEmpty += 1
    11.  
    12. End If
    13.  
    14. End If
    15. Next
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    thanx for reply

    how about the question i want to solve ?
    thanx

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by ninjaX
    thanx for reply

    how about the question i want to solve ?
    thanx
    I thought your question was "How to check if ANY textbox is empty".

    So please clarify your question.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    i have about 21 textbox in my form

    example i got 1 client name textbox and 1 current age textbox and one is profit textbox

    how can i check all the textbox in my form ???

    the client name text box is string
    the current aga textbox is number
    the profit textbox is double

    how to use the for loop to check all the textbox ??

    can someone please help me ???

  6. #6
    Addicted Member
    Join Date
    Apr 2004
    Location
    Lagos, Nigeria
    Posts
    215
    why not use the tag property of the textbox to differentiate the data type of their content to aid you in the loop. For age and profit textboxes, the IsNumeric() function will do......

    Eg.
    VB Code:
    1. Dim ctl As Control
    2. im txtTmp As TextBox
    3.  
    4. For Each Ctr In Me.Controls
    5.  
    6.     If TypeOf ctl Is TextBox Then
    7.         txtTmp = DirectCast(ctl, TextBox)
    8.        
    9.         Select Case txtTmp.Tag
    10.             Case "NUMERIC_DATA"
    11.                 If IsNumeric(txtTmp.Text) then
    12.                     'valid data
    13.                 Else
    14.                     'invalid data found
    15.                 End If
    16.  
    17.             Case "STRING_DATA"
    18.                 If txtTmp.Text.Length > 0 then
    19.                     'valid data
    20.                 Else
    21.                     'invalid data found
    22.                 End If
    23.  
    24.             Case "DATE_DATA"
    25.                 If IsDate(txtTmp.Text) then
    26.                     'valid data
    27.                 Else
    28.                     'invalid data found
    29.                 End If
    30.  
    31.         End select
    32.  
    33.     End If
    34. Next

    Where 'NUMERIC_DATA', 'STRING_DATA' and 'DATE_DATA' represents valid tags for the textboxes set [may be] in the designer.

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by ninjaX
    i have about 21 textbox in my form

    example i got 1 client name textbox and 1 current age textbox and one is profit textbox

    how can i check all the textbox in my form ???

    the client name text box is string
    the current aga textbox is number
    the profit textbox is double

    how to use the for loop to check all the textbox ??

    can someone please help me ???
    Looks like you are harking back to VB6. Every textbox in VB.NET will contain a string. What you have to do is decide on a range of values you consider acceptable. e.g assume age range 15 to 70,
    Name contains only alaphabetic characters. There is no way the entry made into a textbox can be a Double. You can, of course, convert numerical characters entered into whatever other type you wish.

    Are you saying that you have 21 different textboxes each one holding a different type of information - similar to an application form - and you want to check that the content of each textbox is acceptable? Or are you saying you have seven sets of three types of information, Name, Age and Profit?

    You could use the Tag property to indicate whether the contents of the textbox should be Alpha or Numeric or even below or above a specified numeric value or length of text and then check the textbox.text against that requirement.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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