I've create a function that search the datas fom a txtbox,however don't know how to check the input type of txtBox
vInput = txtRecherche.Text
NbCol = dt.Columns.Count
NbRow = dt.Rows.Count
For iVar As Integer = 0 To NbCol - 1
Dim type As String = dt.Columns(iVar).DataType.Name
If IsNumeric(vInput) Then
'here I want to check on vInput if is Integer '
Try
Dim a As Integer = Integer.Parse(vInput)
SearchExpression &= dt.Columns(iVar).ColumnName & " = " & vInput & " or "
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
'checking on vInput if is decimal '
End If
To check for integer. When I tried like this in VB it works.
Protected Sub Button1_Click1(sender As Object, e As System.EventArgs)
Dim str1 As String = TextBox1.Text
If Val(str1) = Math.Round(Val(str1)) Then
Response.Write("It is an Integer")
Else
Response.Write("It is not an Integer")
End If
End Sub
Kindly mark this post as "Answer", if it helped you.
You can use TryParse for each type, as karthic_85 suggests. TryParse will return true if the parse was successful. It will return false if the parse wasn't successful. So you can use if with that.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Wolfoo
0 Points
14 Posts
type Of textbox
May 07, 2012 02:24 PM|LINK
I've create a function that search the datas fom a txtbox,however don't know how to check the input type of txtBox
vInput = txtRecherche.Text NbCol = dt.Columns.Count NbRow = dt.Rows.Count For iVar As Integer = 0 To NbCol - 1 Dim type As String = dt.Columns(iVar).DataType.Name If IsNumeric(vInput) Then 'here I want to check on vInput if is Integer ' Try Dim a As Integer = Integer.Parse(vInput) SearchExpression &= dt.Columns(iVar).ColumnName & " = " & vInput & " or " Catch ex As Exception MsgBox(ex.Message) End Try Else 'checking on vInput if is decimal ' End IfWolfoo
0 Points
14 Posts
Re: type Of textbox
May 07, 2012 02:37 PM|LINK
Some Help please
karthic_85
Contributor
2598 Points
587 Posts
Re: type Of textbox
May 07, 2012 02:40 PM|LINK
int op;
bool rslt=Int32.TryParse("10",out op);
bool rslt2 = Int32.TryParse("1dg0",out op);
rslt will be true & rslt2 will be false
Wolfoo
0 Points
14 Posts
Re: type Of textbox
May 07, 2012 02:54 PM|LINK
sorry but is there a way using the operator if
thanks
basheerkal
Star
10672 Points
2426 Posts
Re: type Of textbox
May 07, 2012 04:22 PM|LINK
Chekch whether the number has decimals
if(vInput==Math.Round(vInput)) { }(Talk less..Work more)
Wolfoo
0 Points
14 Posts
Re: type Of textbox
May 07, 2012 05:42 PM|LINK
it didn't work but thank you
now I'm stucking on the search by DateTime
when I search by datetime an error raise :
cannot perfom 'Like' operation on System.DateTime and System.String
the same with equal '=' operator
basheerkal
Star
10672 Points
2426 Posts
Re: type Of textbox
May 08, 2012 01:41 AM|LINK
To check for integer. When I tried like this in VB it works.
Protected Sub Button1_Click1(sender As Object, e As System.EventArgs) Dim str1 As String = TextBox1.Text If Val(str1) = Math.Round(Val(str1)) Then Response.Write("It is an Integer") Else Response.Write("It is not an Integer") End If End Sub(Talk less..Work more)
superguppie
All-Star
48225 Points
8679 Posts
Re: type Of textbox
May 11, 2012 02:52 PM|LINK
You can use TryParse for each type, as karthic_85 suggests. TryParse will return true if the parse was successful. It will return false if the parse wasn't successful. So you can use if with that.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Madhu1234
Participant
1380 Points
287 Posts
Re: type Of textbox
May 11, 2012 04:42 PM|LINK
string strtxtValue = textbox1.Text;
int result;
if(int.TryParse(strtxtValue,out result)
{
//you can enter this condition only if the value of your textbox is an integer ,then you can implement rest of the logic here
}
Madhu1234
Participant
1380 Points
287 Posts
Re: type Of textbox
May 11, 2012 04:42 PM|LINK
string strtxtValue = textbox1.Text;
int result;
if(int.TryParse(strtxtValue,out result)
{
//you can enter this condition only if the value of your textbox is an integer ,then you can implement rest of the logic here
}