Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
so im comparing numbers with this code

Dim curDGV1Cri1 As Double = dgv1("DGV1Cri1", e.RowIndex).Value
Dim curDGV1Cri2 As Double = dgv1("DGV1Cri2", e.RowIndex).Value
Dim curDGV1Cri3 As Double = dgv1("DGV1Cri3", e.RowIndex).Value
Dim curDGV1Cri4 As Double = dgv1("DGV1Cri4", e.RowIndex).Value
Dim curDGV1Cri5 As Double = dgv1("DGV1Cri5", e.RowIndex).Value
Dim InputString1 As String = DataGridView1.Columns("DGV1Cri1").HeaderText
Dim Result1 As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(InputString1, "\d+")
Dim InputString2 As String = DataGridView1.Columns("DGV1Cri2").HeaderText
Dim Result2 As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(InputString2, "\d+")
Dim InputString3 As String = DataGridView1.Columns("DGV1Cri3").HeaderText
Dim Result3 As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(InputString3, "\d+")
Dim InputString4 As String = DataGridView1.Columns("DGV1Cri4").HeaderText
Dim Result4 As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(InputString4, "\d+")
Dim InputString5 As String = DataGridView1.Columns("DGV1Cri5").HeaderText
Dim Result5 As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(InputString5, "\d+")
Dim InputString6 As String = lblJudge.Text
Dim Result6 As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(InputString6, "\d+")

If curDGV1Cri1 > Result1.Value Then
dgv1("DGV1Cri1", e.RowIndex).Value = "0"
MessageBox.Show("Your input is out of range.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf curDGV1Cri2 > Convert.ToInt32(Result2.Value) Then
dgv1("DGV1Cri2", e.RowIndex).Value = "0"
MessageBox.Show("Your input is out of range.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf curDGV1Cri3 > Convert.ToInt32(Result3.Value) Then
dgv1("DGV1Cri3", e.RowIndex).Value = "0"
MessageBox.Show("Your input is out of range.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf curDGV1Cri4 > Convert.ToInt32(Result4.Value) Then
dgv1("DGV1Cri4", e.RowIndex).Value = "0"
MessageBox.Show("Your input is out of range.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf curDGV1Cri5 > Convert.ToInt32(Result5.Value) Then
dgv1("DGV1Cri5", e.RowIndex).Value = "0"
MessageBox.Show("Your input is out of range.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

for example if the Result1 is equal to 30, its still giving me error even if i input on datagridview cell a number from 4-9.
Posted
Updated 23-Jan-13 23:49pm
v3
Comments
Mike Meinz 23-Jan-13 8:11am    
I am sorry but you have not provided enough information.
-How is curDGV2Cri1 declared?
-How is curDGV2Cri1's value set?
-What does the Visual Studio Debugger Locals window show for the Value and Type of the curDGV2Cri1 and Result1 variables?
Member 9756176 24-Jan-13 5:34am    
i update the question already providing what you ask. curDGV1Cri1 value are numbers, decimal or whole number.

1 solution

Don't do things like that! You are comparing strings, not numbers!
So "10" is less than "1", and so forth. Convert them to numbers, and it should work.

VB
If Convert.ToInt32(curDGV2Cri1) > Convert.ToInt32(Result1.Value) Then
 
Share this answer
 
Comments
Member 9756176 24-Jan-13 5:46am    
how about the extracting numbers from text? it is string, i tried your solution, but it didn't work, i give i try for changing the curDGV2Cri1 As Double, then your Convert.ToInt32 to Convert.ToDouble. it didn't work also

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900