Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8961365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:52:27+00:00 2026-06-15T15:52:27+00:00

This Might be a long question but please do bear with me a little.

  • 0

This Might be a long question but please do bear with me a little.

I have a Datagridview1 on Form1 with the columns BranchCode("cells(2) ,FormCode("cells(3)")), Quantity("cells(5)")

Now Let’s say this is how it looks like

DGV1

 BranchCode | FormCode | Quantity
     001         Frm1       10
     002         Frm2      -10
     001         Frm1       20

Now on DGV2 let’s say I have an data with the same branch code and form code

DGV2

BranchCode | FormCode | Quantity
    001        Frm1        50
    002        Frm2        50

Now the code below loops through DGV1 then sums up all the Quantity with the same FormCode and BranchCode before adding it to DGV2

Ex: DGV1 results

BranchCode | FormCode | Quantity
    001        Frm1        30
    002        Frm2       -10

Then After adding it to DGV2 this would be the result

DGV 2 Results

BranchCode | FormCode | Quantity
    001        Frm1        80
    002        Frm2        40

CODE

For Each xRows In MDIAdjustment.oTransferRows.Where(Function(x) x.Cells("GVPosted").Value.ToString() = "No")

      If (occurences.ContainsKey(xRows.Cells(3).Value.ToString())) Then

          occurences(xRows.Cells(3).Value.ToString()).Quantity = Double.Parse(occurences(xRows.Cells(3).Value.ToString()).ToString()) + Double.Parse(xRows.Cells(5).Value.ToString())

               Else

                    occurences.Add(xRows.Cells(3).Value.ToString(), New CustomValues2 With {.Code = xRows.Cells(3).Value.ToString(), .Branch = xRows.Cells(2).Value.ToString(), .Description = xRows.Cells(4).Value.ToString(), .Quantity = Double.Parse(xRows.Cells(5).Value.ToString()) })  

               End If

     Next

Declaration of occurences dictionary

Dim occurences As New Dictionary(Of String, CustomValues2)

Class CustomValues2 

Public Property Code() As String 
Public Property Branch() As String 
Public Property Description() As String 
Public Property Quantity() As Double 

End Class

The question is, when I compute using only positive integers, I have no problem, but when I start to add negative numbers I get an error on this line

 occurences(xRows.Cells(3).Value.ToString()).Quantity = Double.Parse(occurences(xRows.Cells(3).Value.ToString()).ToString()) + Double.Parse(xRows.Cells(5).Value.ToString())

Saying FormatException was Unhandled" Input string was not in a correct format

Sorry For the long Post, I’ve tried to do things but they don’t remove the error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:52:28+00:00Added an answer on June 15, 2026 at 3:52 pm

    Change your error line to :

    occurences(xRows.Cells(3).Value.ToString()).Quantity = occurences(xRows.Cells(3).Value.ToString()).Quantity + Double.Parse(xRows.Cells(5).Value.ToString())
    

    You need to add to the quantity property, so you need to fetch its current value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this might be an odd question, but I have a map Long-String pair: 10
It might be a long shot posting this question here but we will see.
I know this might be a long shot, but here it goes. I have
This might not be a programming question but I am posting it after long
This might seem like a stupid question but it's been a long day. I'm
This might be a trivial question, but I have not found anything about it,
This might seem like a little bit of a nit picky question, but I
:) This might look to be a very long question to you I understand,
Firstly, This might seem like a long question. I don't think it is... The
This might seem like a very easy question for some of you folks, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.