|
-
Jul 3rd, 2004, 06:30 AM
#1
Thread Starter
Lively Member
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
-
Jul 3rd, 2004, 06:43 AM
#2
PowerPoster
Hi,
Just a couple of changes, assuming that you want the variable CheckTextBoxIsEmpty to hold the number of empty textboxes.
VB Code:
Dim Ctr As Control
Dim CheckTextBoxIsEmpty AS Integer =0
For Each Ctr In Me.Controls
If TypeOf Ctr Is TextBox Then
If Ctr.Text = "" Then
CheckTextBoxIsEmpty += 1
End If
End If
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.
-
Jul 3rd, 2004, 06:56 AM
#3
Thread Starter
Lively Member
thanx for reply
how about the question i want to solve ?
thanx
-
Jul 3rd, 2004, 07:19 AM
#4
PowerPoster
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.
-
Jul 3rd, 2004, 07:24 AM
#5
Thread Starter
Lively Member
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 ???
-
Jul 3rd, 2004, 11:44 AM
#6
Addicted Member
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:
Dim ctl As Control
im txtTmp As TextBox
For Each Ctr In Me.Controls
If TypeOf ctl Is TextBox Then
txtTmp = DirectCast(ctl, TextBox)
Select Case txtTmp.Tag
Case "NUMERIC_DATA"
If IsNumeric(txtTmp.Text) then
'valid data
Else
'invalid data found
End If
Case "STRING_DATA"
If txtTmp.Text.Length > 0 then
'valid data
Else
'invalid data found
End If
Case "DATE_DATA"
If IsDate(txtTmp.Text) then
'valid data
Else
'invalid data found
End If
End select
End If
Next
Where 'NUMERIC_DATA', 'STRING_DATA' and 'DATE_DATA' represents valid tags for the textboxes set [may be] in the designer.
-
Jul 3rd, 2004, 04:29 PM
#7
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|