Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all, The below code displays result in 1,234.00 number format. So
if I have amount 2,000.49 in cell one and 2,000.01 in cell two of datagridview the result should be 4,000.50 but below code displays it 4,001.00. How can I get the the decimals? Also if I want result to be 4,001 instead of 4,001.00 in other words amount without decimals then how can I achive it in below code. Please can any friend tell me that what amendment in below code can give me the result i am looking for. Private Sub DataGridViewX2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridViewX2.SelectionChanged Dim OBC As Integer = 0 Dim currentRow As DataGridViewCell For Each currentRow In DataGridViewX2.SelectedCells If currentRow.ColumnIndex = 6 And DataGridViewX2.SelectedCells.Count 1 Then OBC += CInt(currentRow.Value) ElseIf currentRow.ColumnIndex = 9 And DataGridViewX2.SelectedCells.Count 1 Then OBC += CInt(currentRow.Value) Else OBC += 0 End If Next LabelItem2.Visible = True LabelItem3.Visible = True If Microsoft.VisualBasic.Left(OBC.ToString, 1) = "-" Then LabelItem3.Text = OBC.ToString("N") LabelItem3.ForeColor = Color.Red Else LabelItem3.Text = OBC.ToString("N") LabelItem3.ForeColor = Color.Black End If End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
K pretended :
Hi all, The below code displays result in 1,234.00 number format. So if I have amount 2,000.49 in cell one and 2,000.01 in cell two of datagridview the result should be 4,000.50 but below code displays it 4,001.00. How can I get the the decimals? Also if I want result to be 4,001 instead of 4,001.00 in other words amount without decimals then how can I achive it in below code. Please can any friend tell me that what amendment in below code can give me the result i am looking for. Private Sub DataGridViewX2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridViewX2.SelectionChanged Dim OBC As Integer = 0 Dim currentRow As DataGridViewCell For Each currentRow In DataGridViewX2.SelectedCells If currentRow.ColumnIndex = 6 And DataGridViewX2.SelectedCells.Count 1 Then OBC += CInt(currentRow.Value) ElseIf currentRow.ColumnIndex = 9 And DataGridViewX2.SelectedCells.Count 1 Then OBC += CInt(currentRow.Value) Else OBC += 0 End If Next LabelItem2.Visible = True LabelItem3.Visible = True If Microsoft.VisualBasic.Left(OBC.ToString, 1) = "-" Then LabelItem3.Text = OBC.ToString("N") LabelItem3.ForeColor = Color.Red Else LabelItem3.Text = OBC.ToString("N") LabelItem3.ForeColor = Color.Black End If End Sub This is a MS Excel group. The programming language here is VBA. You need to ask this in a dotnet group... microsoft.public.dotnet.languages.vb ...for example. -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
K wrote:
Hi all, The below code displays result in 1,234.00 number format. So if I have amount 2,000.49 in cell one and 2,000.01 in cell two of datagridview the result should be 4,000.50 but below code displays it 4,001.00. How can I get the the decimals? Also if I want result to be 4,001 instead of 4,001.00 in other words amount without decimals then how can I achive it in below code. Please can any friend tell me that what amendment in below code can give me the result i am looking for. Private Sub DataGridViewX2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridViewX2.SelectionChanged Dim OBC As Integer = 0 Dim currentRow As DataGridViewCell For Each currentRow In DataGridViewX2.SelectedCells If currentRow.ColumnIndex = 6 And DataGridViewX2.SelectedCells.Count 1 Then OBC += CInt(currentRow.Value) ElseIf currentRow.ColumnIndex = 9 And DataGridViewX2.SelectedCells.Count 1 Then OBC += CInt(currentRow.Value) Else OBC += 0 End If Next LabelItem2.Visible = True LabelItem3.Visible = True If Microsoft.VisualBasic.Left(OBC.ToString, 1) = "-" Then LabelItem3.Text = OBC.ToString("N") LabelItem3.ForeColor = Color.Red Else LabelItem3.Text = OBC.ToString("N") LabelItem3.ForeColor = Color.Black End If End Sub The problem is that you're working with integers. Change OBC to a floating- point type (Dim OBC As Single = 0) and remove both occurences of "CInt" (OBC += currentRow.Value), see if that fixes things. ....but I agree with Garry, this question should really be asked in a .Net group. -- - You're a good person. - How do you know that? - Because you're nothing like me. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Jan 28, 12:13*am, "Auric__" wrote:
K wrote: Hi all, The below code displays result in 1,234.00 number format. *So if I have amount 2,000.49 in cell one and 2,000.01 in cell two of datagridview the result should be 4,000.50 but below code displays it 4,001.00. *How can I get the the decimals? *Also if I want result to be 4,001 instead of 4,001.00 in other words amount without decimals then how can I achive it in below code. Please can any friend tell me that what amendment in below code can give me the result i am looking for. *Private Sub DataGridViewX2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridViewX2.SelectionChanged * * * * Dim OBC As Integer = 0 * * * * Dim currentRow As DataGridViewCell * * * * For Each currentRow In DataGridViewX2.SelectedCells * * * * * * If currentRow.ColumnIndex = 6 And DataGridViewX2.SelectedCells.Count 1 Then * * * * * * * * OBC += CInt(currentRow.Value) * * * * * * ElseIf currentRow.ColumnIndex = 9 And DataGridViewX2.SelectedCells.Count 1 Then * * * * * * * * OBC += CInt(currentRow.Value) * * * * * * Else * * * * * * * * OBC += 0 * * * * * * End If * * * * Next * * * * LabelItem2.Visible = True * * * * LabelItem3.Visible = True * * * * If Microsoft.VisualBasic.Left(OBC.ToString, 1) = "-" Then * * * * * * LabelItem3.Text = OBC.ToString("N") * * * * * * LabelItem3.ForeColor = Color.Red * * * * Else * * * * * * LabelItem3.Text = OBC.ToString("N") * * * * * * LabelItem3.ForeColor = Color.Black * * * * End If * * End Sub The problem is that you're working with integers. Change OBC to a floating- point type (Dim OBC As Single = 0) and remove both occurences of "CInt" (OBC += currentRow.Value), see if that fixes things. ...but I agree with Garry, this question should really be asked in a .Net group. -- - You're a good person. * - How do you know that? - Because you're nothing like me.- Hide quoted text - - Show quoted text - Thanks Auric. Sorry to post this question to wrong place |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Replace million-billion number format to lakhs-crores format | Excel Discussion (Misc queries) | |||
Change number (in text format) to numeric format | Excel Discussion (Misc queries) | |||
convert text-format number to number in excel 2000%3f | Excel Discussion (Misc queries) | |||
Number format based on number format of another cell in another workbook | Excel Programming | |||
excel format cells/Number/Category: Number problem | Excel Discussion (Misc queries) |