Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 23-Jan-13 1:16am
Edited 23-Jan-13 23:49pm
v3
Comments
Mike Meinz at 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 at 24-Jan-13 5:34am
   
i update the question already providing what you ask. curDGV1Cri1 value are numbers, decimal or whole number.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
If Convert.ToInt32(curDGV2Cri1) > Convert.ToInt32(Result1.Value) Then
  Permalink  
Comments
Member 9756176 at 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)

  Print Answers RSS
0 OriginalGriff 414
1 Maciej Los 180
2 Richard MacCutchan 140
3 DamithSL 129
4 Kornfeld Eliyahu Peter 119


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid